render 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +8 -8
  2. data/Gemfile +1 -1
  3. data/lib/render.rb +12 -50
  4. data/lib/render/{array_attribute.rb → attributes/array_attribute.rb} +3 -4
  5. data/lib/render/attributes/attribute.rb +48 -0
  6. data/lib/render/{hash_attribute.rb → attributes/hash_attribute.rb} +2 -4
  7. data/lib/render/definition.rb +31 -0
  8. data/lib/render/extensions/dottable_hash.rb +82 -0
  9. data/lib/render/extensions/symbolizable_array.rb +26 -0
  10. data/lib/render/extensions/symbolizable_hash.rb +28 -0
  11. data/lib/render/generator.rb +58 -4
  12. data/lib/render/graph.rb +29 -34
  13. data/lib/render/schema.rb +12 -12
  14. data/lib/render/type.rb +63 -0
  15. data/lib/render/version.rb +1 -1
  16. data/rakefile.rb +3 -3
  17. data/readme.md +17 -38
  18. data/render.gemspec +5 -7
  19. data/spec/functional/{representation → render}/attribute_spec.rb +3 -4
  20. data/spec/functional/{representation → render}/graph_spec.rb +6 -6
  21. data/spec/functional/{representation → render}/nested_schemas_spec.rb +0 -0
  22. data/spec/functional/{representation → render}/schema_spec.rb +0 -0
  23. data/spec/integration/render/graph_spec.rb +119 -0
  24. data/spec/integration/render/nested_graph_spec.rb +67 -0
  25. data/spec/integration/render/schema_spec.rb +90 -0
  26. data/spec/support/helpers.rb +2 -1
  27. data/spec/{schemas → support/schemas}/film.json +1 -0
  28. data/spec/{schemas → support/schemas}/films.json +1 -0
  29. data/spec/unit/gemspec_spec.rb +8 -0
  30. data/spec/unit/{array_attribute_spec.rb → render/attributes/array_attribute_spec.rb} +1 -1
  31. data/spec/unit/render/{attribute_spec.rb → attributes/attribute_spec.rb} +0 -0
  32. data/spec/unit/render/{hash_attribute_spec.rb → attributes/hash_attribute_spec.rb} +3 -1
  33. data/spec/unit/render/definition_spec.rb +85 -0
  34. data/spec/unit/render/extensions/dottable_hash_spec.rb +148 -0
  35. data/spec/unit/render/extensions/symbolizable_array_spec.rb +20 -0
  36. data/spec/unit/render/generator_spec.rb +44 -22
  37. data/spec/unit/render/graph_spec.rb +18 -18
  38. data/spec/unit/render/schema_spec.rb +11 -16
  39. data/spec/unit/render/type_spec.rb +83 -0
  40. data/spec/unit/render_spec.rb +0 -139
  41. metadata +70 -60
  42. data/lib/extensions/boolean.rb +0 -2
  43. data/lib/extensions/enumerable.rb +0 -16
  44. data/lib/extensions/hash.rb +0 -39
  45. data/lib/render/attribute.rb +0 -59
  46. data/lib/render/dottable_hash.rb +0 -113
  47. data/spec/integration/nested_graph_spec.rb +0 -85
  48. data/spec/integration/single_graph_spec.rb +0 -76
  49. data/spec/unit/extensions/boolean_spec.rb +0 -7
  50. data/spec/unit/render/dottable_hash_spec.rb +0 -231
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Weber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-19 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: uuid
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,61 +53,61 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.3.7
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: debugger
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.6'
69
69
  - !ruby/object:Gem::Dependency
70
- name: debugger
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '2.14'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '2.14'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '1.17'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '1.17'
97
97
  - !ruby/object:Gem::Dependency
98
- name: webmock
98
+ name: yard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '0.8'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '0.8'
111
111
  description: Simple management of API calls.
112
112
  email:
113
113
  - steve@copyright1984.com
@@ -123,40 +123,45 @@ files:
123
123
  - Gemfile.lock
124
124
  - LICENSE.txt
125
125
  - initialize.rb
126
- - lib/extensions/boolean.rb
127
- - lib/extensions/enumerable.rb
128
- - lib/extensions/hash.rb
129
126
  - lib/render.rb
130
- - lib/render/array_attribute.rb
131
- - lib/render/attribute.rb
132
- - lib/render/dottable_hash.rb
127
+ - lib/render/attributes/array_attribute.rb
128
+ - lib/render/attributes/attribute.rb
129
+ - lib/render/attributes/hash_attribute.rb
130
+ - lib/render/definition.rb
133
131
  - lib/render/errors.rb
132
+ - lib/render/extensions/dottable_hash.rb
133
+ - lib/render/extensions/symbolizable_array.rb
134
+ - lib/render/extensions/symbolizable_hash.rb
134
135
  - lib/render/generator.rb
135
136
  - lib/render/graph.rb
136
- - lib/render/hash_attribute.rb
137
137
  - lib/render/schema.rb
138
+ - lib/render/type.rb
138
139
  - lib/render/version.rb
139
140
  - rakefile.rb
140
141
  - readme.md
141
142
  - render.gemspec
142
- - spec/functional/representation/attribute_spec.rb
143
- - spec/functional/representation/graph_spec.rb
144
- - spec/functional/representation/nested_schemas_spec.rb
145
- - spec/functional/representation/schema_spec.rb
146
- - spec/integration/nested_graph_spec.rb
147
- - spec/integration/single_graph_spec.rb
148
- - spec/schemas/film.json
149
- - spec/schemas/films.json
143
+ - spec/functional/render/attribute_spec.rb
144
+ - spec/functional/render/graph_spec.rb
145
+ - spec/functional/render/nested_schemas_spec.rb
146
+ - spec/functional/render/schema_spec.rb
147
+ - spec/integration/render/graph_spec.rb
148
+ - spec/integration/render/nested_graph_spec.rb
149
+ - spec/integration/render/schema_spec.rb
150
150
  - spec/support.rb
151
151
  - spec/support/helpers.rb
152
- - spec/unit/array_attribute_spec.rb
153
- - spec/unit/extensions/boolean_spec.rb
154
- - spec/unit/render/attribute_spec.rb
155
- - spec/unit/render/dottable_hash_spec.rb
152
+ - spec/support/schemas/film.json
153
+ - spec/support/schemas/films.json
154
+ - spec/unit/gemspec_spec.rb
155
+ - spec/unit/render/attributes/array_attribute_spec.rb
156
+ - spec/unit/render/attributes/attribute_spec.rb
157
+ - spec/unit/render/attributes/hash_attribute_spec.rb
158
+ - spec/unit/render/definition_spec.rb
159
+ - spec/unit/render/extensions/dottable_hash_spec.rb
160
+ - spec/unit/render/extensions/symbolizable_array_spec.rb
156
161
  - spec/unit/render/generator_spec.rb
157
162
  - spec/unit/render/graph_spec.rb
158
- - spec/unit/render/hash_attribute_spec.rb
159
163
  - spec/unit/render/schema_spec.rb
164
+ - spec/unit/render/type_spec.rb
160
165
  - spec/unit/render_spec.rb
161
166
  homepage: https://github.com/stevenweber/render
162
167
  licenses:
@@ -178,28 +183,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
183
  version: '0'
179
184
  requirements: []
180
185
  rubyforge_project:
181
- rubygems_version: 2.1.11
186
+ rubygems_version: 2.2.1
182
187
  signing_key:
183
188
  specification_version: 4
184
189
  summary: With a JSON schema, Render will manage requests, dependent request and build
185
190
  meaningful, extensible sample data for testing.
186
191
  test_files:
187
- - spec/functional/representation/attribute_spec.rb
188
- - spec/functional/representation/graph_spec.rb
189
- - spec/functional/representation/nested_schemas_spec.rb
190
- - spec/functional/representation/schema_spec.rb
191
- - spec/integration/nested_graph_spec.rb
192
- - spec/integration/single_graph_spec.rb
193
- - spec/schemas/film.json
194
- - spec/schemas/films.json
192
+ - spec/functional/render/attribute_spec.rb
193
+ - spec/functional/render/graph_spec.rb
194
+ - spec/functional/render/nested_schemas_spec.rb
195
+ - spec/functional/render/schema_spec.rb
196
+ - spec/integration/render/graph_spec.rb
197
+ - spec/integration/render/nested_graph_spec.rb
198
+ - spec/integration/render/schema_spec.rb
195
199
  - spec/support.rb
196
200
  - spec/support/helpers.rb
197
- - spec/unit/array_attribute_spec.rb
198
- - spec/unit/extensions/boolean_spec.rb
199
- - spec/unit/render/attribute_spec.rb
200
- - spec/unit/render/dottable_hash_spec.rb
201
+ - spec/support/schemas/film.json
202
+ - spec/support/schemas/films.json
203
+ - spec/unit/gemspec_spec.rb
204
+ - spec/unit/render/attributes/array_attribute_spec.rb
205
+ - spec/unit/render/attributes/attribute_spec.rb
206
+ - spec/unit/render/attributes/hash_attribute_spec.rb
207
+ - spec/unit/render/definition_spec.rb
208
+ - spec/unit/render/extensions/dottable_hash_spec.rb
209
+ - spec/unit/render/extensions/symbolizable_array_spec.rb
201
210
  - spec/unit/render/generator_spec.rb
202
211
  - spec/unit/render/graph_spec.rb
203
- - spec/unit/render/hash_attribute_spec.rb
204
212
  - spec/unit/render/schema_spec.rb
213
+ - spec/unit/render/type_spec.rb
205
214
  - spec/unit/render_spec.rb
215
+ has_rdoc:
@@ -1,2 +0,0 @@
1
- class Boolean
2
- end
@@ -1,16 +0,0 @@
1
- ::Enumerable.module_eval do
2
- # This is named the same as its Hash counterpart for a reason. I'm not
3
- # going to tell you why, consider it my riddle for you.
4
- def recursive_symbolize_keys!
5
- each do |item|
6
- item.recursive_symbolize_keys! if item.respond_to?(:recursive_symbolize_keys!)
7
- end
8
- self
9
- end
10
-
11
- def recursive_stringify_keys!
12
- each do |item|
13
- item.recursive_stringify_keys! if item.respond_to?(:recursive_stringify_keys!)
14
- end
15
- end
16
- end
@@ -1,39 +0,0 @@
1
- class ::Hash
2
- def stringify_keys!
3
- keys.each do |key|
4
- self[key.to_s] = delete(key)
5
- end
6
- self
7
- end
8
-
9
- def stringify_keys
10
- dup.stringify_keys!
11
- end
12
-
13
- def recursive_stringify_keys!
14
- stringify_keys!
15
- values.each do |value|
16
- value.recursive_stringify_keys! if value.respond_to?(:recursive_stringify_keys!)
17
- end
18
- self
19
- end
20
-
21
- def symbolize_keys!
22
- keys.each do |key|
23
- self[(key.to_sym rescue key) || key] = delete(key)
24
- end
25
- self
26
- end
27
-
28
- def recursive_symbolize_keys!
29
- symbolize_keys!
30
- values.each do |value|
31
- value.recursive_symbolize_keys! if value.respond_to?(:recursive_symbolize_keys!)
32
- end
33
- self
34
- end
35
-
36
- def symbolize_keys
37
- dup.symbolize_keys!
38
- end
39
- end
@@ -1,59 +0,0 @@
1
- # An Attribute represents a specific key and value as part of a Schema.
2
- # It is responsible for casting its value and generating sample data.
3
-
4
- require "uuid"
5
-
6
- module Render
7
- class Attribute
8
- SCHEMA_IDENTIFIERS = [:properties, :items].freeze
9
-
10
- attr_accessor :name,
11
- :type,
12
- :schema,
13
- :enums,
14
- :format,
15
- :required
16
-
17
- def initialize(options = {})
18
- Render.logger.debug("Initializing attribute #{options}")
19
- self.required = false
20
- end
21
-
22
- def generator
23
- @generator ||= Render.generators.detect do |generator|
24
- generator.type == type && name.match(generator.matcher)
25
- end
26
- end
27
-
28
- def bias_type
29
- format || type
30
- end
31
-
32
- def default_value
33
- Render.live ? nil : faux_value
34
- end
35
-
36
- def nested_schema?(options = {})
37
- options.any? { |name, value| SCHEMA_IDENTIFIERS.include?(name) }
38
- end
39
-
40
- private
41
-
42
- def faux_value
43
- return enums.sample if enums
44
- return generator.algorithm.call if generator
45
-
46
- case(bias_type.name)
47
- when("String") then "#{name} (generated)"
48
- when("Integer") then rand(1000)
49
- when("UUID") then UUID.generate
50
- when("Boolean") then [true, false].sample
51
- when("Float") then rand(0.1..99).round(2)
52
- when("Time")
53
- time = Time.now
54
- (type == String) ? time.to_s : time
55
- end
56
- end
57
-
58
- end
59
- end
@@ -1,113 +0,0 @@
1
- module Render
2
- class DottableHash < Hash
3
- class << self
4
- def new(element_to_hash = {})
5
- hash = super().merge!(element_to_hash.symbolize_keys)
6
- hash.each do |key, value|
7
- hash[key] = initialize_element(value)
8
- end
9
- hash
10
- end
11
-
12
- def initialize_element(value)
13
- case value
14
- when Hash
15
- new(value)
16
- when Array
17
- value.collect { |v| initialize_element(v) }
18
- else
19
- value
20
- end
21
- end
22
- end
23
-
24
- def []=(key, value)
25
- key = key.to_sym
26
- value = self.class.initialize_element(value)
27
- super
28
- end
29
-
30
- def [](key)
31
- key = key.to_sym
32
- super
33
- end
34
-
35
- def delete(key)
36
- key = key.to_sym
37
- super
38
- end
39
-
40
- def has_key?(key)
41
- super(key.to_sym)
42
- end
43
-
44
- def merge!(other_hash)
45
- super(other_hash.symbolize_keys)
46
- end
47
-
48
- def merge(other_hash)
49
- super(other_hash.symbolize_keys)
50
- end
51
-
52
- def method_missing(method, *arguments)
53
- if method.match(/\=$/)
54
- self[method.to_s.chop] = arguments.first
55
- elsif has_key?(method)
56
- self[method]
57
- else
58
- super
59
- end
60
- end
61
-
62
- def fetch(key, *args)
63
- key = key.to_sym
64
- super
65
- end
66
-
67
- def fetch_path(full_path)
68
- begin
69
- fetch_path!(full_path)
70
- rescue KeyError
71
- nil
72
- end
73
- end
74
-
75
- def fetch_path!(full_path)
76
- full_path.split(".").inject(self) do |hash, path|
77
- raise(KeyError) unless hash.is_a?(Hash)
78
-
79
- hash.fetch(path)
80
- end
81
- end
82
-
83
- def set_path(full_path, value)
84
- self.dup.set_path!(full_path, value)
85
- end
86
-
87
- def set_path!(full_path, value)
88
- built_hash_for_value = full_path.split(".").reverse.inject({}) do |cumulative, path_to_source|
89
- if cumulative.empty?
90
- { path_to_source.to_sym => value }
91
- else
92
- { path_to_source.to_sym => cumulative }
93
- end
94
- end
95
-
96
- deep_merge!(built_hash_for_value)
97
- end
98
-
99
- protected
100
-
101
- def deep_merge(other_hash)
102
- merge(other_hash) do |key, oldval, newval|
103
- oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
104
- newval = newval.to_hash if newval.respond_to?(:to_hash)
105
- oldval.is_a?(Hash) && newval.is_a?(Hash) ? self.class.new(oldval).deep_merge(newval) : self.class.new(newval)
106
- end
107
- end
108
-
109
- def deep_merge!(other_hash)
110
- replace(deep_merge(other_hash))
111
- end
112
- end
113
- end