kosher 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ module Kosher
4
+ class Struct < ::Struct
5
+ def to_map
6
+ map = Hash.new
7
+ self.members.each { |m| map[m] = self[m] }
8
+ map
9
+ end
10
+
11
+ def to_json(*a)
12
+ to_map.to_json(*a)
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Kosher
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.12'
3
3
  end
data/lib/kosher.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'sucker'
2
+ require 'kosher/struct'
2
3
  require 'kosher/algorithm'
3
4
  require 'kosher/condition'
4
5
  require 'kosher/description'
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  module Kosher
4
4
  describe Item do
5
+ it "should descend from Kosher::Struct" do
6
+ Item.ancestors.should include Kosher::Struct
7
+ end
8
+
5
9
  describe ".build" do
6
10
  use_vcr_cassette '0143105825'
7
11
 
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Kosher
4
+ describe Struct do
5
+ before(:all) do
6
+ class Foo < Struct.new(:bar); end
7
+ end
8
+
9
+ describe "to_json" do
10
+ it "converts to JSON" do
11
+ foo = Foo.new
12
+ foo.bar = 1
13
+
14
+ foo.to_json.should eql "{\"bar\":1}"
15
+ end
16
+
17
+ it "handles nested structs" do
18
+ foo_1 = Foo.new
19
+ foo_2 = Foo.new
20
+
21
+ foo_2.bar = 1
22
+ foo_1.bar = foo_2
23
+
24
+ foo_1.to_json.should eql "{\"bar\":{\"bar\":1}}"
25
+ end
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.11
5
+ version: 0.1.12
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paper Cavalier
@@ -114,6 +114,7 @@ files:
114
114
  - lib/kosher/offer.rb
115
115
  - lib/kosher/request.rb
116
116
  - lib/kosher/seller.rb
117
+ - lib/kosher/struct.rb
117
118
  - lib/kosher/version.rb
118
119
  - spec/fabricators/condition_fabricator.rb
119
120
  - spec/fabricators/offer_fabricator.rb
@@ -127,6 +128,7 @@ files:
127
128
  - spec/kosher/offer_spec.rb
128
129
  - spec/kosher/request_spec.rb
129
130
  - spec/kosher/seller_spec.rb
131
+ - spec/kosher/struct_spec.rb
130
132
  - spec/spec_helper.rb
131
133
  - spec/support/credentials.rb
132
134
  - spec/support/faker.rb
@@ -173,6 +175,7 @@ test_files:
173
175
  - spec/kosher/offer_spec.rb
174
176
  - spec/kosher/request_spec.rb
175
177
  - spec/kosher/seller_spec.rb
178
+ - spec/kosher/struct_spec.rb
176
179
  - spec/spec_helper.rb
177
180
  - spec/support/credentials.rb
178
181
  - spec/support/faker.rb