Hey Guys I need some help. This post may be long, but I'll do my best to
keep it to the details.
I have a old environment I've been tasked with moving from 1.8.6 to 1.9.3
This environment has a custom library that is used by a bunch of different
ruby applications. The portion I'm having issue with right now is it used
to use Facets/OpenCascade, so when it would load the YML you would get a
object back(hash) that you could reference like a.b.c(or config.db)
Anyhow Facets appears to have removed a bunch of this and gone to more core
libs, but I found the gem Hashery and it seems like it will do what I want.
But I can't not get the call to work. I keep getting wrong # of arguments
on initialize. Below is my code and exception.
yml:
Code:
db:
database: dbserver
host: sql01
user: user
password: password
load_config.rb
Code:
config = YAML::load(IO.read(File.join(@path, "environment.yml")))
config.merge!(YAML::load(IO.read(File.join(@path,
"environments/#{@environment}.yml"))))
@config = Hashery::OpenCascade.new(config)
open_cascade.rb
Code:
class OpenCascade < OpenHash
def initialize(*default)
@read = {}
leet = lambda { |h,k| h[k] = OpenCascade.new(&leet) }
super(*default, &leet)
end
open_hash.rb
Code:
class OpenHash < CRUDHash
def initialize(default=nil, safe=false, &block)
@safe = safe
super(*[default].compact, &block) *<-- my debug throws the exception here*
end
crud_hash.rb <-- there is no initialize method here, which is one of my
confusion points. I don't understand what it's init'ing I can attach this
class if need be.
Exception:
Code:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/hashery-2.0.1/lib/hashery/open_hash.rb:36:in
`initialize': wrong number of argu
ments (ArgumentError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/hashery-2.0.1/lib/hashery/open_hash.rb:36:in
`initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/hashery-2.0.1/lib/hashery/open_cascade.rb:65:in
`initialize'
I'll provide whatever else is needed. Thanks in advance!
I think the problem comes from the fact that you're passing both a default
value and a block to Hash#initialize (since CRUDHash doesn't override it). If
you look at the documentation for Hash#initialize, you'll see that only one of
the two may be given.
I hope this helps
Stefano
···
On Tuesday 30 April 2013 Daniel Stephens wrote
Hey Guys I need some help. This post may be long, but I'll do my best to
keep it to the details.
I have a old environment I've been tasked with moving from 1.8.6 to 1.9.3
This environment has a custom library that is used by a bunch of different
ruby applications. The portion I'm having issue with right now is it used
to use Facets/OpenCascade, so when it would load the YML you would get a
object back(hash) that you could reference like a.b.c(or config.db)
Anyhow Facets appears to have removed a bunch of this and gone to more core
libs, but I found the gem Hashery and it seems like it will do what I want.
But I can't not get the call to work. I keep getting wrong # of arguments
on initialize. Below is my code and exception.
yml:
Code:
db:
database: dbserver
host: sql01
user: user
password: password
load_config.rb
Code:
config = YAML::load(IO.read(File.join(@path, "environment.yml")))
config.merge!(YAML::load(IO.read(File.join(@path,
"environments/#{@environment}.yml"))))
@config = Hashery::OpenCascade.new(config)
open_cascade.rb
Code:
class OpenCascade < OpenHash
def initialize(*default)
@read = {}
leet = lambda { |h,k| h[k] = OpenCascade.new(&leet) }
super(*default, &leet)
end
open_hash.rb
Code:
class OpenHash < CRUDHash
def initialize(default=nil, safe=false, &block)
@safe = safe
super(*[default].compact, &block) *<-- my debug throws the exception
here* end
crud_hash.rb <-- there is no initialize method here, which is one of my
confusion points. I don't understand what it's init'ing I can attach this
class if need be.
Exception:
Code:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/hashery-2.0.1/lib/hashery/open_hash.rb:3
6:in `initialize': wrong number of argu
ments (ArgumentError)
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/hashery-2.0.1/lib/hashery/open_hash.rb:
36:in `initialize'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/hashery-2.0.1/lib/hashery/open_cascade.
rb:65:in `initialize'
I'll provide whatever else is needed. Thanks in advance!