Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made the proxy use ActiveSupport::BasicObject

  • Loading branch information...
commit 685fad4cf2c76b6b0b7e221584144bc6ca400982 1 parent ee3e79d
@akiellor authored
View
4 Gemfile.lock
@@ -1,11 +1,13 @@
PATH
remote: .
specs:
- objectify (0.0.1)
+ objectify (0.0.2)
+ activesupport (>= 2.3)
GEM
remote: http://rubygems.org/
specs:
+ activesupport (3.0.5)
diff-lcs (1.1.2)
rake (0.8.7)
rspec (2.5.0)
View
14 lib/objectify.rb
@@ -1,20 +1,22 @@
-module Objectify
- class Proxy
- def == other
- @target == other
- end
+require 'active_support'
+module Objectify
+ class Proxy < ActiveSupport::BasicObject
def initialize target
@target = target
end
def method_missing name, *args, &block
- if @target.is_a?(Hash) && @target.has_key?(name)
+ if @target.respond_to?(:has_key?) && @target.has_key?(name)
Proxy.new @target[name]
else
Proxy.new @target.send(name, *args, &block)
end
end
+
+ def send name, *args, &block
+ method_missing name.to_sym, *args, &block
+ end
end
def objectify
View
1  objectify.gemspec
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+ s.add_dependency('activesupport', '>= 2.3')
s.add_development_dependency('rspec')
s.add_development_dependency('rake')
end
View
3  spec/objectify_spec.rb
@@ -7,7 +7,8 @@
subject { {:key => "value", :another_key => "another value"}.objectify }
its(:key) { should == "value" }
- its(:another_key) { should == "another value" }
+ it { subject.another_key.should == "another value" }
+ it { subject.send(:key).should == "value" }
end
describe "an objectified hash with nested hashes" do
Please sign in to comment.
Something went wrong with that request. Please try again.