json-generator 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,3 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'json/generator'
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "json/generator/version"
2
4
 
3
5
  require "json/generator/basic_attribute"
@@ -7,6 +9,7 @@ require "json/generator/integer_attribute"
7
9
  require "json/generator/array_attribute"
8
10
  require "json/generator/object_attribute"
9
11
  require "json/generator/boolean_attribute"
12
+ require "json/generator/number_attribute"
10
13
  require "json/generator/attribute_factory"
11
14
  require "json/generator/dereferencer"
12
15
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class ArrayAttribute < BasicAttribute
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class AttributeFactory
@@ -7,8 +9,9 @@ module JSON
7
9
  'integer' => IntegerAttribute,
8
10
  'array' => ArrayAttribute,
9
11
  'boolean' => BooleanAttribute,
10
- nil => EmptyAttribute
12
+ 'number' => NumberAttribute,
11
13
  }
14
+ CLASSES.default = EmptyAttribute
12
15
 
13
16
  def self.create(properties)
14
17
  CLASSES[Array(properties['type']).first].new(properties)
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class BasicAttribute
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class BooleanAttribute < BasicAttribute
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class Dereferencer
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class EmptyAttribute < BasicAttribute
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class IntegerAttribute < BasicAttribute
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module JSON
4
+ module Generator
5
+ class NumberAttribute < BasicAttribute
6
+ DEFAULT_VALUE = 0.0
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class ObjectAttribute < BasicAttribute
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  class StringAttribute < BasicAttribute
@@ -1,5 +1,7 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
- VERSION = "0.0.1"
5
+ VERSION = "0.1.0"
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe ArrayAttribute do
@@ -7,7 +9,7 @@ module JSON
7
9
 
8
10
  describe '#generate' do
9
11
  context 'with minItems' do
10
- it 'should generate an array with two objects of the expected type' do
12
+ it 'should generate an array with the minimum number of items of the expected type' do
11
13
  stubbed_item = stub('item', :generate => 'foo')
12
14
  AttributeFactory.should_receive(:create).twice.
13
15
  with('type' => 'dummy_type').
@@ -1,10 +1,12 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe AttributeFactory do
4
6
  describe '.create' do
5
7
  let(:attribute) { stub('attribute') }
6
8
 
7
- context 'when type is a string' do
9
+ context 'when type is string' do
8
10
  let(:properties) { {'type' => 'string'} }
9
11
 
10
12
  it 'should create a StringAttribute' do
@@ -13,7 +15,7 @@ module JSON
13
15
  end
14
16
  end
15
17
 
16
- context 'when type is an object' do
18
+ context 'when type is object' do
17
19
  let(:properties) { {'type' => 'object'} }
18
20
 
19
21
  it 'should create an ObjectAttribute' do
@@ -22,7 +24,7 @@ module JSON
22
24
  end
23
25
  end
24
26
 
25
- context 'when type is an array' do
27
+ context 'when type is array' do
26
28
  let(:properties) { {'type' => 'array'} }
27
29
 
28
30
  it 'should create an ArrayAttribute' do
@@ -31,7 +33,7 @@ module JSON
31
33
  end
32
34
  end
33
35
 
34
- context 'when type is an integer' do
36
+ context 'when type is integer' do
35
37
  let(:properties) { {'type' => 'integer'} }
36
38
 
37
39
  it 'should create an IntegerAttribute' do
@@ -40,7 +42,7 @@ module JSON
40
42
  end
41
43
  end
42
44
 
43
- context 'when type is a boolean' do
45
+ context 'when type is boolean' do
44
46
  let(:properties) { {'type' => 'boolean'} }
45
47
 
46
48
  it 'should create a BooleanAttribute' do
@@ -49,10 +51,37 @@ module JSON
49
51
  end
50
52
  end
51
53
 
52
- context 'when we have an array of types' do
54
+ context 'when type is number' do
55
+ let(:properties) { {'type' => 'number'} }
56
+
57
+ it 'should create a NumberAttribute' do
58
+ NumberAttribute.should_receive(:new).with(properties).and_return(attribute)
59
+ described_class.create(properties).should == attribute
60
+ end
61
+ end
62
+
63
+ context 'when type is null' do
64
+ let(:properties) { {'type' => 'null'} }
65
+
66
+ it 'should create an EmptyAttribute' do
67
+ EmptyAttribute.should_receive(:new).with(properties).and_return(attribute)
68
+ described_class.create(properties).should == attribute
69
+ end
70
+ end
71
+
72
+ context 'when type is any' do
73
+ let(:properties) { {'type' => 'any'} }
74
+
75
+ it 'should create an EmptyAttribute' do
76
+ EmptyAttribute.should_receive(:new).with(properties).and_return(attribute)
77
+ described_class.create(properties).should == attribute
78
+ end
79
+ end
80
+
81
+ context 'when there is more than one type' do
53
82
  let(:properties) { {'type' => ['string', 'boolean']} }
54
83
 
55
- it 'should create a the default attribute for the first type' do
84
+ it 'should create an attribute for the first type' do
56
85
  StringAttribute.should_receive(:new).with(properties).and_return(attribute)
57
86
  described_class.create(properties).should == attribute
58
87
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe BasicAttribute do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe BooleanAttribute do
@@ -7,7 +9,7 @@ module JSON
7
9
 
8
10
  describe '#generate' do
9
11
  context 'without a default value' do
10
- it 'should return the default value' do
12
+ it 'should return false' do
11
13
  described_class.new({'type' => 'boolean'}).generate.should == false
12
14
  end
13
15
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe Dereferencer do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe EmptyAttribute do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe IntegerAttribute do
@@ -7,7 +9,7 @@ module JSON
7
9
 
8
10
  describe '#generate' do
9
11
  context 'without a default value' do
10
- it 'should return the default value' do
12
+ it 'should return 0' do
11
13
  described_class.new({'type' => 'integer'}).generate.should == 0
12
14
  end
13
15
  end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module JSON
4
+ module Generator
5
+ describe NumberAttribute do
6
+ it 'should be a BasicAttribute' do
7
+ described_class.new(nil).should be_kind_of(BasicAttribute)
8
+ end
9
+
10
+ describe '#generate' do
11
+ context 'without a default value' do
12
+ it 'should return 0.0' do
13
+ described_class.new({'type' => 'number'}).generate.should == 0.0
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe ObjectAttribute do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  module Generator
3
5
  describe StringAttribute do
@@ -7,7 +9,7 @@ module JSON
7
9
 
8
10
  describe '#generate' do
9
11
  context 'without a default value' do
10
- it 'should return the default value' do
12
+ it 'should return bar' do
11
13
  described_class.new({'type' => 'string'}).generate.should == 'bar'
12
14
  end
13
15
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module JSON
2
4
  describe Generator do
3
5
  describe '.generate' do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'json'
2
4
  require 'json-schema'
3
5
  require 'json-generator'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-28 00:00:00.000000000 Z
12
+ date: 2013-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json-schema
@@ -89,6 +89,7 @@ files:
89
89
  - lib/json/generator/dereferencer.rb
90
90
  - lib/json/generator/empty_attribute.rb
91
91
  - lib/json/generator/integer_attribute.rb
92
+ - lib/json/generator/number_attribute.rb
92
93
  - lib/json/generator/object_attribute.rb
93
94
  - lib/json/generator/string_attribute.rb
94
95
  - lib/json/generator/version.rb
@@ -101,6 +102,7 @@ files:
101
102
  - spec/json/generator/dereferencer_spec.rb
102
103
  - spec/json/generator/empty_attribute_spec.rb
103
104
  - spec/json/generator/integer_attribute_spec.rb
105
+ - spec/json/generator/number_attribute_spec.rb
104
106
  - spec/json/generator/object_attribute_spec.rb
105
107
  - spec/json/generator/string_attribute_spec.rb
106
108
  - spec/json/generator_spec.rb
@@ -120,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
122
  version: '0'
121
123
  segments:
122
124
  - 0
123
- hash: -1314970676245074753
125
+ hash: 1309752435689555124
124
126
  required_rubygems_version: !ruby/object:Gem::Requirement
125
127
  none: false
126
128
  requirements:
@@ -129,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
131
  version: '0'
130
132
  segments:
131
133
  - 0
132
- hash: -1314970676245074753
134
+ hash: 1309752435689555124
133
135
  requirements: []
134
136
  rubyforge_project:
135
137
  rubygems_version: 1.8.24
@@ -144,6 +146,7 @@ test_files:
144
146
  - spec/json/generator/dereferencer_spec.rb
145
147
  - spec/json/generator/empty_attribute_spec.rb
146
148
  - spec/json/generator/integer_attribute_spec.rb
149
+ - spec/json/generator/number_attribute_spec.rb
147
150
  - spec/json/generator/object_attribute_spec.rb
148
151
  - spec/json/generator/string_attribute_spec.rb
149
152
  - spec/json/generator_spec.rb