lib/polaroid.rb in polaroid-0.0.3 vs lib/polaroid.rb in polaroid-0.0.4
- old
+ new
@@ -1,8 +1,8 @@
class Polaroid < Module
- VERSION = "0.0.3"
+ VERSION = "0.0.4"
def initialize(*messages)
@messages = messages
@polaroid_struct_class = ImmutableStruct.new(*messages)
define_capture_method
@@ -29,15 +29,17 @@
define_method(:take_snapshot, &take_snapshot)
end
module ClassMethods
- def build_from_snapshot(snapshot_hash, format = :hash)
+ def build_from_snapshot(snapshot, format = :hash)
case format
when :hash
- # This line intentionally left blank
+ snapshot_hash = snapshot.map.with_object({}) do |(k, v), hash|
+ hash[k.to_sym] = v
+ end
when :json
- snapshot_hash = JSON.parse(snapshot_hash).map.with_object({}) do |(k, v), hash|
+ snapshot_hash = JSON.parse(snapshot).map.with_object({}) do |(k, v), hash|
hash[k.to_sym] = v
end
end
self::Snapshot.new(snapshot_hash)
end