Permalink
Browse files

Extract method now also returns stringified keys.

Change-Id: Ib6177dd5e85d23811f5fb7fb448cdff73d024536
  • Loading branch information...
1 parent 5334b66 commit 8a5168cb33ae53c8fb509ba38f2390a7b8829add @kowshik kowshik committed Jul 19, 2012
Showing with 13 additions and 4 deletions.
  1. +7 −2 lib/json_message.rb
  2. +4 −0 spec/unit/json_message_spec.rb
  3. +2 −2 vcap_common.gemspec
View
@@ -152,8 +152,13 @@ def encode
Yajl::Encoder.encode(@msg)
end
- def extract
- @msg.dup.freeze
+ def extract(opts = {})
+ hash = @msg.dup
+ if opts[:stringify_keys]
+ hash = hash.inject({}) { |memo,(k,v)| memo[k.to_s] = v; memo }.freeze
+ end
+
+ hash.freeze
end
protected
@@ -254,8 +254,12 @@
@klass.optional :optional, String, "default"
msg = @klass.new
msg.required = "required"
+
extracted = msg.extract
extracted.should == {:required => "required", :optional => "default"}
+
+ extracted = msg.extract(:stringify_keys => true)
+ extracted.should == {"required" => "required", "optional" => "default"}
end
end
end
View
@@ -1,6 +1,6 @@
spec = Gem::Specification.new do |s|
s.name = 'vcap_common'
- s.version = '2.0.0'
+ s.version = '2.0.1'
s.date = '2012-07-05'
s.summary = 'vcap common'
s.homepage = "http://github.com/vmware-ac/core"
@@ -14,7 +14,7 @@ spec = Gem::Specification.new do |s|
s.add_dependency('yajl-ruby', '~> 0.8.3')
s.add_dependency('nats', '~> 0.4.22.beta.8')
s.add_dependency('posix-spawn', '~> 0.3.6')
- s.add_dependency('membrane')
+ s.add_dependency('membrane', '~> 0.0.2')
s.add_development_dependency('rake', '~> 0.9.2')
s.require_paths = ['lib']

0 comments on commit 8a5168c

Please sign in to comment.