Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding .no_lazy to get a marshable hash

  • Loading branch information...
commit 4aff0b1bcc0a07de781a4e7d8dc5b84222e6c589 1 parent ae91184
@rogercampos authored
Showing with 23 additions and 7 deletions.
  1. +4 −0 lib/lazyhash.rb
  2. +19 −7 spec/lazyhash_spec.rb
View
4 lib/lazyhash.rb
@@ -14,5 +14,9 @@ def build_hash
lazy = lambda { |h,k| h[k] = Hash.new(&lazy) }
Hash.new(&lazy)
end
+
+ def no_lazy(hash)
+ eval(hash.inspect)
+ end
end
end
View
26 spec/lazyhash_spec.rb
@@ -5,6 +5,10 @@
@hash = LazyHash.build_hash
end
+ it "should not be marshable" do
+ lambda { Marshal.dump(@hash) }.should raise_error
+ end
+
describe ".add" do
it "should assign consecutive values with different deep's" do
LazyHash.add(@hash, "es.projects.title", "Main title")
@@ -35,13 +39,21 @@
end
end
- describe ".add!" do
- it "should assign consecutive values with different deep's"
- it "should raise an error when overwriting a folder"
- it "should raise an error when overwriting a file"
- end
-
describe ".no_lazy" do
- it "should return a copy of the given Hash without the proc constructor"
+ it "should return a copy of the given hash" do
+ LazyHash.add(@hash, "es.projects", "Proyectos")
+ unlazy = LazyHash.no_lazy(@hash)
+ unlazy.should == {"es" => {"projects" => "Proyectos"}}
+ end
+
+ it "should return a copy of the given hash without the proc constructor" do
+ unlazy = LazyHash.no_lazy(@hash)
+ unlazy.default_proc.should be_nil
+ end
+
+ it "should return a marshable hash" do
+ unlazy = LazyHash.no_lazy(@hash)
+ lambda { Marshal.dump(unlazy) }.should_not raise_error
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.