praxis-blueprints 3.0 → 3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -0
- data/.travis.yml +10 -5
- data/CHANGELOG.md +27 -0
- data/Gemfile +1 -0
- data/Guardfile +13 -7
- data/README.md +8 -3
- data/Rakefile +4 -3
- data/lib/praxis-blueprints.rb +2 -1
- data/lib/praxis-blueprints/blueprint.rb +96 -87
- data/lib/praxis-blueprints/collection_view.rb +15 -10
- data/lib/praxis-blueprints/config_hash.rb +15 -12
- data/lib/praxis-blueprints/field_expander.rb +60 -48
- data/lib/praxis-blueprints/finalizable.rb +4 -8
- data/lib/praxis-blueprints/renderer.rb +50 -19
- data/lib/praxis-blueprints/version.rb +2 -1
- data/lib/praxis-blueprints/view.rb +22 -29
- data/praxis-blueprints.gemspec +37 -24
- data/spec/praxis-blueprints/blueprint_spec.rb +84 -58
- data/spec/praxis-blueprints/collection_view_spec.rb +16 -7
- data/spec/praxis-blueprints/config_hash_spec.rb +64 -0
- data/spec/praxis-blueprints/field_expander_spec.rb +46 -38
- data/spec/praxis-blueprints/renderer_spec.rb +128 -40
- data/spec/praxis-blueprints/view_spec.rb +24 -10
- data/spec/spec_helper.rb +14 -14
- data/spec/support/spec_blueprints.rb +32 -8
- metadata +112 -35
@@ -1,7 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative '../spec_helper'
|
2
3
|
|
3
4
|
describe Praxis::View do
|
4
|
-
|
5
5
|
let(:person) { Person.example(['person']) }
|
6
6
|
let(:address) { person.address }
|
7
7
|
|
@@ -34,7 +34,7 @@ describe Praxis::View do
|
|
34
34
|
subject(:contents) { view.contents }
|
35
35
|
its(:keys) { should match_array([:name, :email, :full_name, :parents, :address, :prior_addresses, :work_address]) }
|
36
36
|
it 'saves attributes defined on the Blueprint' do
|
37
|
-
[:name, :email, :full_name
|
37
|
+
[:name, :email, :full_name].each do |attr|
|
38
38
|
contents[attr].should be Person.attributes[attr]
|
39
39
|
end
|
40
40
|
end
|
@@ -49,7 +49,6 @@ describe Praxis::View do
|
|
49
49
|
contents[:prior_addresses].contents.should eq Address.views[:state].contents
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
52
|
context 'creating subviews' do
|
54
53
|
it 'creates subviews when a block is used' do
|
55
54
|
contents[:parents].should be_kind_of(Praxis::View)
|
@@ -72,28 +71,43 @@ describe Praxis::View do
|
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
74
|
+
context 'that reference the enclosing view' do
|
75
|
+
let(:view) { Person.views.fetch(:self_referencing) }
|
76
|
+
context 'for non-collection attributes' do
|
77
|
+
it 'the view points exactly to parent view' do
|
78
|
+
contents[:myself].should be_kind_of(Praxis::View)
|
79
|
+
contents[:myself].should be(view)
|
80
|
+
contents[:myself].contents.should eq(view.contents)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
context 'for collection attributes' do
|
84
|
+
it 'creates the sub-CollectionViews with a member view with the same contents of the parent' do
|
85
|
+
contents[:friends].should be_kind_of(Praxis::CollectionView)
|
86
|
+
contents[:friends].contents.should eq(view.contents)
|
87
|
+
contents[:friends].contents.keys.should match_array([:myself, :friends])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
75
91
|
end
|
76
|
-
|
77
92
|
end
|
78
93
|
|
79
94
|
context '#describe' do
|
80
|
-
subject(:description) { view.describe}
|
81
|
-
its(:keys){ should =~ [:attributes, :type] }
|
95
|
+
subject(:description) { view.describe }
|
96
|
+
its(:keys) { should =~ [:attributes, :type] }
|
82
97
|
its([:type]) { should eq(:standard) }
|
83
98
|
context 'returns attributes' do
|
84
99
|
subject { description[:attributes] }
|
85
100
|
|
86
|
-
its(:keys){ should match_array view.contents.keys }
|
101
|
+
its(:keys) { should match_array view.contents.keys }
|
87
102
|
|
88
103
|
it 'should return empty hashes for attributes with no specially defined view' do
|
89
104
|
subject[:name].should eq({})
|
90
105
|
subject[:email].should eq({})
|
91
106
|
end
|
92
107
|
it 'should return the view name if specified' do
|
93
|
-
subject[:address].should eq(
|
94
|
-
subject[:prior_addresses].should eq(
|
108
|
+
subject[:address].should eq(view: :extended)
|
109
|
+
subject[:prior_addresses].should eq(view: :state)
|
95
110
|
end
|
96
111
|
end
|
97
112
|
end
|
98
|
-
|
99
113
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
|
1
5
|
Encoding.default_external = Encoding::UTF_8
|
2
6
|
|
3
7
|
require 'rubygems'
|
4
8
|
require 'bundler/setup'
|
5
9
|
|
6
10
|
# Configure simplecov gem (must be here at top of file)
|
7
|
-
#require 'simplecov'
|
8
|
-
#SimpleCov.start do
|
11
|
+
# require 'simplecov'
|
12
|
+
# SimpleCov.start do
|
9
13
|
# add_filter 'spec' # Don't include RSpec stuff
|
10
|
-
#end
|
14
|
+
# end
|
11
15
|
|
12
|
-
|
13
|
-
|
16
|
+
# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
+
# $LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
18
|
$LOAD_PATH.unshift 'lib'
|
15
19
|
|
16
20
|
Bundler.setup(:default, :development, :test)
|
17
21
|
Bundler.require(:default, :development, :test)
|
18
22
|
|
19
|
-
|
20
23
|
require 'praxis-blueprints'
|
21
24
|
|
22
25
|
require_relative 'support/spec_blueprints'
|
23
26
|
|
24
|
-
|
25
27
|
RSpec.configure do |config|
|
26
28
|
config.backtrace_exclusion_patterns = [
|
27
|
-
|
28
|
-
/
|
29
|
+
%r{/lib/\d*/ruby/},
|
30
|
+
%r{bin/},
|
29
31
|
/gems/,
|
30
|
-
/
|
31
|
-
/
|
32
|
-
/
|
32
|
+
%r{spec/spec_helper.rb},
|
33
|
+
%r{lib/rspec/(core|expectations|matchers|mocks)},
|
34
|
+
%r{org/jruby/.*.java}
|
33
35
|
]
|
34
36
|
|
35
37
|
config.before(:suite) do
|
36
38
|
Praxis::Blueprint.finalize!
|
37
39
|
end
|
38
|
-
|
39
|
-
|
40
40
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class Person < Praxis::Blueprint
|
2
3
|
attributes do
|
3
4
|
attribute :name, String, example: /[:first_name:]/
|
@@ -20,6 +21,9 @@ class Person < Praxis::Blueprint
|
|
20
21
|
attribute :tags, Attributor::Collection.of(String)
|
21
22
|
attribute :href, String
|
22
23
|
attribute :alive, Attributor::Boolean, default: true
|
24
|
+
attribute :myself, Person
|
25
|
+
attribute :friends, Attributor::Collection.of(Person)
|
26
|
+
attribute :metadata, Attributor::Hash
|
23
27
|
end
|
24
28
|
|
25
29
|
view :default do
|
@@ -29,6 +33,15 @@ class Person < Praxis::Blueprint
|
|
29
33
|
attribute :prior_addresses
|
30
34
|
end
|
31
35
|
|
36
|
+
view :circular do
|
37
|
+
attribute :address, view: :circular
|
38
|
+
end
|
39
|
+
|
40
|
+
view :self_referencing do
|
41
|
+
attribute :myself, view: :self_referencing
|
42
|
+
attribute :friends, view: :self_referencing
|
43
|
+
end
|
44
|
+
|
32
45
|
view :current do
|
33
46
|
attribute :name
|
34
47
|
attribute :full_name
|
@@ -46,18 +59,16 @@ class Person < Praxis::Blueprint
|
|
46
59
|
attribute :address
|
47
60
|
attribute :alive
|
48
61
|
end
|
49
|
-
|
50
62
|
end
|
51
63
|
|
52
|
-
|
53
|
-
class Address < Praxis::Blueprint
|
64
|
+
class Address < Praxis::Blueprint
|
54
65
|
attributes do
|
55
66
|
attribute :id, Integer
|
56
67
|
attribute :name, String
|
57
68
|
attribute :street, String
|
58
|
-
attribute :state, String, values: %w
|
69
|
+
attribute :state, String, values: %w(OR CA)
|
59
70
|
|
60
|
-
attribute :resident, Person, example: proc { |address,context| Person.example(context, address: address) }
|
71
|
+
attribute :resident, Person, example: proc { |address, context| Person.example(context, address: address) }
|
61
72
|
end
|
62
73
|
|
63
74
|
view :default do
|
@@ -65,6 +76,9 @@ class Address < Praxis::Blueprint
|
|
65
76
|
attribute :state
|
66
77
|
end
|
67
78
|
|
79
|
+
view :circular do
|
80
|
+
attribute :resident, view: :circular
|
81
|
+
end
|
68
82
|
view :state do
|
69
83
|
attribute :state
|
70
84
|
end
|
@@ -74,15 +88,25 @@ class Address < Praxis::Blueprint
|
|
74
88
|
attribute :street
|
75
89
|
attribute :resident
|
76
90
|
end
|
77
|
-
|
78
91
|
end
|
79
92
|
|
80
|
-
|
81
93
|
class FullName < Attributor::Model
|
82
|
-
|
83
94
|
attributes do
|
84
95
|
attribute :first, String, example: /[:first_name:]/
|
85
96
|
attribute :last, String, example: /[:last_name:]/
|
86
97
|
end
|
98
|
+
end
|
87
99
|
|
100
|
+
class SimpleHash < Attributor::Model
|
101
|
+
attributes do
|
102
|
+
attribute :id, Integer
|
103
|
+
attribute :hash, Hash
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class SimpleHashCollection < Attributor::Model
|
108
|
+
attributes do
|
109
|
+
attribute :id, Integer
|
110
|
+
attribute :hash_collection, Attributor::Collection.of(Hash)
|
111
|
+
end
|
88
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: praxis-blueprints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '3.
|
4
|
+
version: '3.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep M. Blanquer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: randexp
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '5.5'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '5.5'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: activesupport
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,28 +57,28 @@ dependencies:
|
|
57
57
|
name: bundler
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rake
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
@@ -99,16 +99,16 @@ dependencies:
|
|
99
99
|
name: yard
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0
|
104
|
+
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: 0
|
111
|
+
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: guard
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,75 +141,150 @@ dependencies:
|
|
141
141
|
name: rspec
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- - "
|
144
|
+
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
146
|
+
version: '0'
|
147
147
|
type: :development
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
|
-
- - "
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: rspec-its
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
152
159
|
- !ruby/object:Gem::Version
|
153
|
-
version: '
|
160
|
+
version: '0'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: rspec-collection_matchers
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
154
182
|
- !ruby/object:Gem::Dependency
|
155
183
|
name: pry
|
156
184
|
requirement: !ruby/object:Gem::Requirement
|
157
185
|
requirements:
|
158
|
-
- - "
|
186
|
+
- - ">="
|
159
187
|
- !ruby/object:Gem::Version
|
160
188
|
version: '0'
|
161
189
|
type: :development
|
162
190
|
prerelease: false
|
163
191
|
version_requirements: !ruby/object:Gem::Requirement
|
164
192
|
requirements:
|
165
|
-
- - "
|
193
|
+
- - ">="
|
166
194
|
- !ruby/object:Gem::Version
|
167
195
|
version: '0'
|
168
196
|
- !ruby/object:Gem::Dependency
|
169
197
|
name: pry-byebug
|
170
198
|
requirement: !ruby/object:Gem::Requirement
|
171
199
|
requirements:
|
172
|
-
- - "
|
200
|
+
- - ">="
|
173
201
|
- !ruby/object:Gem::Version
|
174
|
-
version: '
|
202
|
+
version: '0'
|
175
203
|
type: :development
|
176
204
|
prerelease: false
|
177
205
|
version_requirements: !ruby/object:Gem::Requirement
|
178
206
|
requirements:
|
179
|
-
- - "
|
207
|
+
- - ">="
|
180
208
|
- !ruby/object:Gem::Version
|
181
|
-
version: '
|
209
|
+
version: '0'
|
182
210
|
- !ruby/object:Gem::Dependency
|
183
211
|
name: pry-stack_explorer
|
184
212
|
requirement: !ruby/object:Gem::Requirement
|
185
213
|
requirements:
|
186
|
-
- - "
|
214
|
+
- - ">="
|
187
215
|
- !ruby/object:Gem::Version
|
188
216
|
version: '0'
|
189
217
|
type: :development
|
190
218
|
prerelease: false
|
191
219
|
version_requirements: !ruby/object:Gem::Requirement
|
192
220
|
requirements:
|
193
|
-
- - "
|
221
|
+
- - ">="
|
194
222
|
- !ruby/object:Gem::Version
|
195
223
|
version: '0'
|
196
224
|
- !ruby/object:Gem::Dependency
|
197
225
|
name: fuubar
|
198
226
|
requirement: !ruby/object:Gem::Requirement
|
199
227
|
requirements:
|
200
|
-
- - "
|
228
|
+
- - ">="
|
201
229
|
- !ruby/object:Gem::Version
|
202
|
-
version: '
|
230
|
+
version: '0'
|
203
231
|
type: :development
|
204
232
|
prerelease: false
|
205
233
|
version_requirements: !ruby/object:Gem::Requirement
|
206
234
|
requirements:
|
207
|
-
- - "
|
235
|
+
- - ">="
|
208
236
|
- !ruby/object:Gem::Version
|
209
|
-
version: '
|
210
|
-
|
211
|
-
|
212
|
-
|
237
|
+
version: '0'
|
238
|
+
- !ruby/object:Gem::Dependency
|
239
|
+
name: coveralls
|
240
|
+
requirement: !ruby/object:Gem::Requirement
|
241
|
+
requirements:
|
242
|
+
- - ">="
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: '0'
|
245
|
+
type: :development
|
246
|
+
prerelease: false
|
247
|
+
version_requirements: !ruby/object:Gem::Requirement
|
248
|
+
requirements:
|
249
|
+
- - ">="
|
250
|
+
- !ruby/object:Gem::Version
|
251
|
+
version: '0'
|
252
|
+
- !ruby/object:Gem::Dependency
|
253
|
+
name: rubocop
|
254
|
+
requirement: !ruby/object:Gem::Requirement
|
255
|
+
requirements:
|
256
|
+
- - ">="
|
257
|
+
- !ruby/object:Gem::Version
|
258
|
+
version: '0'
|
259
|
+
type: :development
|
260
|
+
prerelease: false
|
261
|
+
version_requirements: !ruby/object:Gem::Requirement
|
262
|
+
requirements:
|
263
|
+
- - ">="
|
264
|
+
- !ruby/object:Gem::Version
|
265
|
+
version: '0'
|
266
|
+
- !ruby/object:Gem::Dependency
|
267
|
+
name: guard-rubocop
|
268
|
+
requirement: !ruby/object:Gem::Requirement
|
269
|
+
requirements:
|
270
|
+
- - ">="
|
271
|
+
- !ruby/object:Gem::Version
|
272
|
+
version: '0'
|
273
|
+
type: :development
|
274
|
+
prerelease: false
|
275
|
+
version_requirements: !ruby/object:Gem::Requirement
|
276
|
+
requirements:
|
277
|
+
- - ">="
|
278
|
+
- !ruby/object:Gem::Version
|
279
|
+
version: '0'
|
280
|
+
description: |2
|
281
|
+
Praxis Blueprints is a library that allows for defining a reusable class
|
282
|
+
structures that has a set of typed attributes and a set of views with which
|
283
|
+
to render them. Instantiations of Blueprints resemble ruby Structs which
|
284
|
+
respond to methods of the attribute names. Rendering is format-agnostic in
|
285
|
+
that it results in a structured hash instead of an encoded string.
|
286
|
+
Blueprints can automatically generate object structures that follow the
|
287
|
+
attribute definitions.
|
213
288
|
email:
|
214
289
|
- blanquer@gmail.com
|
215
290
|
- dane.jensen@gmail.com
|
@@ -219,6 +294,7 @@ extra_rdoc_files: []
|
|
219
294
|
files:
|
220
295
|
- ".gitignore"
|
221
296
|
- ".rspec"
|
297
|
+
- ".rubocop.yml"
|
222
298
|
- ".travis.yml"
|
223
299
|
- CHANGELOG.md
|
224
300
|
- Gemfile
|
@@ -238,6 +314,7 @@ files:
|
|
238
314
|
- praxis-blueprints.gemspec
|
239
315
|
- spec/praxis-blueprints/blueprint_spec.rb
|
240
316
|
- spec/praxis-blueprints/collection_view_spec.rb
|
317
|
+
- spec/praxis-blueprints/config_hash_spec.rb
|
241
318
|
- spec/praxis-blueprints/field_expander_spec.rb
|
242
319
|
- spec/praxis-blueprints/renderer_spec.rb
|
243
320
|
- spec/praxis-blueprints/view_spec.rb
|
@@ -263,7 +340,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
340
|
version: '0'
|
264
341
|
requirements: []
|
265
342
|
rubyforge_project:
|
266
|
-
rubygems_version: 2.
|
343
|
+
rubygems_version: 2.6.14
|
267
344
|
signing_key:
|
268
345
|
specification_version: 4
|
269
346
|
summary: Attributes, views, rendering and example generation for common Blueprint
|
@@ -271,9 +348,9 @@ summary: Attributes, views, rendering and example generation for common Blueprin
|
|
271
348
|
test_files:
|
272
349
|
- spec/praxis-blueprints/blueprint_spec.rb
|
273
350
|
- spec/praxis-blueprints/collection_view_spec.rb
|
351
|
+
- spec/praxis-blueprints/config_hash_spec.rb
|
274
352
|
- spec/praxis-blueprints/field_expander_spec.rb
|
275
353
|
- spec/praxis-blueprints/renderer_spec.rb
|
276
354
|
- spec/praxis-blueprints/view_spec.rb
|
277
355
|
- spec/spec_helper.rb
|
278
356
|
- spec/support/spec_blueprints.rb
|
279
|
-
has_rdoc:
|