Skip to content

Commit

Permalink
Merge pull request #12 from cbeer/master
Browse files Browse the repository at this point in the history
fix issue #11; Ruby 1.9 subclasses of Procs behave differently than in 1.8.
  • Loading branch information
mbklein committed Aug 23, 2012
2 parents aa8cc95 + 699f305 commit 146e701
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/confstruct/hash_with_struct_access.rb
Expand Up @@ -2,7 +2,11 @@
require 'confstruct/utils'

module Confstruct
class Deferred < Proc
class Deferred
attr_reader :block
def initialize &block
@block = block
end
def inspect(full=false)
if full
super
Expand Down Expand Up @@ -77,7 +81,7 @@ def initialize hash = @@hash_class.new
def [] key
result = structurize! super(symbolize!(key))
if result.is_a?(Deferred)
result = eval_or_yield self, &result
result = eval_or_yield self, &result.block
end
result
end
Expand Down Expand Up @@ -236,4 +240,4 @@ def do_deep_merge! source, target
end

end
end
end
9 changes: 7 additions & 2 deletions spec/confstruct/hash_with_struct_access_spec.rb
Expand Up @@ -181,7 +181,8 @@
:default_branch => 'master',
:regular_proc => lambda { |a,b,c| puts "#{a}: #{b} #{c}" },
:reverse_url => Confstruct.deferred { self.url.reverse },
:upcase_url => Confstruct.deferred { |c| c.url.upcase }
:upcase_url => Confstruct.deferred { |c| c.url.upcase },
:introspective => Confstruct.deferred { |c| c }
}
}
end
Expand Down Expand Up @@ -239,6 +240,10 @@
@hwsa.github.local_hello.should == 'Bonjour, Monde!'
@hwsa.github.local_time.should == 'French Time!'
end

it "should send the confstruct object as a parameter when evaluating the deferred" do
@hwsa.github.introspective.should be_a_kind_of(Confstruct::HashWithStructAccess)
end

end

Expand All @@ -264,4 +269,4 @@
end
end

end
end

0 comments on commit 146e701

Please sign in to comment.