render 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -1
- data/lib/render.rb +12 -50
- data/lib/render/{array_attribute.rb → attributes/array_attribute.rb} +3 -4
- data/lib/render/attributes/attribute.rb +48 -0
- data/lib/render/{hash_attribute.rb → attributes/hash_attribute.rb} +2 -4
- data/lib/render/definition.rb +31 -0
- data/lib/render/extensions/dottable_hash.rb +82 -0
- data/lib/render/extensions/symbolizable_array.rb +26 -0
- data/lib/render/extensions/symbolizable_hash.rb +28 -0
- data/lib/render/generator.rb +58 -4
- data/lib/render/graph.rb +29 -34
- data/lib/render/schema.rb +12 -12
- data/lib/render/type.rb +63 -0
- data/lib/render/version.rb +1 -1
- data/rakefile.rb +3 -3
- data/readme.md +17 -38
- data/render.gemspec +5 -7
- data/spec/functional/{representation → render}/attribute_spec.rb +3 -4
- data/spec/functional/{representation → render}/graph_spec.rb +6 -6
- data/spec/functional/{representation → render}/nested_schemas_spec.rb +0 -0
- data/spec/functional/{representation → render}/schema_spec.rb +0 -0
- data/spec/integration/render/graph_spec.rb +119 -0
- data/spec/integration/render/nested_graph_spec.rb +67 -0
- data/spec/integration/render/schema_spec.rb +90 -0
- data/spec/support/helpers.rb +2 -1
- data/spec/{schemas → support/schemas}/film.json +1 -0
- data/spec/{schemas → support/schemas}/films.json +1 -0
- data/spec/unit/gemspec_spec.rb +8 -0
- data/spec/unit/{array_attribute_spec.rb → render/attributes/array_attribute_spec.rb} +1 -1
- data/spec/unit/render/{attribute_spec.rb → attributes/attribute_spec.rb} +0 -0
- data/spec/unit/render/{hash_attribute_spec.rb → attributes/hash_attribute_spec.rb} +3 -1
- data/spec/unit/render/definition_spec.rb +85 -0
- data/spec/unit/render/extensions/dottable_hash_spec.rb +148 -0
- data/spec/unit/render/extensions/symbolizable_array_spec.rb +20 -0
- data/spec/unit/render/generator_spec.rb +44 -22
- data/spec/unit/render/graph_spec.rb +18 -18
- data/spec/unit/render/schema_spec.rb +11 -16
- data/spec/unit/render/type_spec.rb +83 -0
- data/spec/unit/render_spec.rb +0 -139
- metadata +70 -60
- data/lib/extensions/boolean.rb +0 -2
- data/lib/extensions/enumerable.rb +0 -16
- data/lib/extensions/hash.rb +0 -39
- data/lib/render/attribute.rb +0 -59
- data/lib/render/dottable_hash.rb +0 -113
- data/spec/integration/nested_graph_spec.rb +0 -85
- data/spec/integration/single_graph_spec.rb +0 -76
- data/spec/unit/extensions/boolean_spec.rb +0 -7
- 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
|
+
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-
|
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: '
|
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: '
|
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:
|
56
|
+
name: debugger
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
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: '
|
68
|
+
version: '1.6'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
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: '
|
82
|
+
version: '2.14'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: webmock
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
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: '
|
96
|
+
version: '1.17'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
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/
|
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/
|
143
|
-
- spec/functional/
|
144
|
-
- spec/functional/
|
145
|
-
- spec/functional/
|
146
|
-
- spec/integration/
|
147
|
-
- spec/integration/
|
148
|
-
- spec/
|
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/
|
153
|
-
- spec/
|
154
|
-
- spec/unit/
|
155
|
-
- spec/unit/render/
|
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
|
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/
|
188
|
-
- spec/functional/
|
189
|
-
- spec/functional/
|
190
|
-
- spec/functional/
|
191
|
-
- spec/integration/
|
192
|
-
- spec/integration/
|
193
|
-
- spec/
|
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/
|
198
|
-
- spec/
|
199
|
-
- spec/unit/
|
200
|
-
- spec/unit/render/
|
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:
|
data/lib/extensions/boolean.rb
DELETED
@@ -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
|
data/lib/extensions/hash.rb
DELETED
@@ -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
|
data/lib/render/attribute.rb
DELETED
@@ -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
|
data/lib/render/dottable_hash.rb
DELETED
@@ -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
|