Permalink
Browse files

Got HashWithName working with initializing through []

  • Loading branch information...
1 parent db3ddb1 commit 9276b0d9f0a66c1465e35f3676183eec20a8eb3d Mark Evans committed Dec 19, 2011
Showing with 14 additions and 0 deletions.
  1. +6 −0 lib/dragonfly/hash_with_name.rb
  2. +8 −0 spec/dragonfly/hash_with_name_spec.rb
@@ -5,6 +5,12 @@ module Dragonfly
# updating ext/basename also updates the name
class HashWithName < Hash
+ def self.[](hash)
+ new_hash = super
+ new_hash[:name] = hash[:name] if hash[:name] # Make sure the name= method gets called
+ new_hash
+ end
+
def [](key)
[:name, :basename, :ext].include?(key) ? send(key) : super
end
@@ -66,4 +66,12 @@
end
end
+ describe "initializing with []" do
+ it "should still work" do
+ hash = Dragonfly::HashWithName[:name => 'mark.duggan']
+ hash[:name].should == 'mark.duggan'
+ hash[:ext].should == 'duggan'
+ end
+ end
+
end

0 comments on commit 9276b0d

Please sign in to comment.