rackson 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
@@ -16,4 +16,12 @@ module Rackson
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ def serializable_hash
21
+ {}.tap do |result|
22
+ self.class.instance_variable_get(:@json_properties).each do |property|
23
+ result[property.name] = self.send(property.name)
24
+ end
25
+ end
26
+ end
19
27
  end
@@ -0,0 +1,3 @@
1
+ * 0.0.2
2
+ -------
3
+ - add Rackson::ObjectMapper#serialize
@@ -13,6 +13,10 @@ module Rackson
13
13
  end
14
14
  end
15
15
 
16
+ def serialize(input)
17
+ JSON.dump(input.serializable_hash)
18
+ end
19
+
16
20
  def deserialize_from_hash(hash, klass)
17
21
  klass.new.tap do |instance|
18
22
  klass.instance_variable_get(:@json_properties).each do |property|
@@ -1,3 +1,3 @@
1
1
  module Rackson
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -6,6 +6,8 @@ describe Rackson::ObjectMapper do
6
6
  class DifferentFakeObject
7
7
  include Rackson
8
8
  json_property :baz, String
9
+
10
+ attr_writer :baz
9
11
  end
10
12
 
11
13
  class FakeObject
@@ -61,4 +63,11 @@ describe Rackson::ObjectMapper do
61
63
  expect(deserialized.first.baz).to eq 'foo'
62
64
  end
63
65
  end
66
+
67
+ describe '#serialize' do
68
+ let(:object) { object = DifferentFakeObject.new; object.baz = 'foo'; object }
69
+ it 'only uses the fields declared as json_properties' do
70
+ expect(mapper.serialize(object)).to eq '{"baz":"foo"}'
71
+ end
72
+ end
64
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -88,6 +88,7 @@ files:
88
88
  - README.md
89
89
  - Rakefile
90
90
  - lib/rackson.rb
91
+ - lib/rackson/CHANGELOG
91
92
  - lib/rackson/object_mapper.rb
92
93
  - lib/rackson/property.rb
93
94
  - lib/rackson/version.rb