praxis-blueprints 3.3 → 3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2baa109dab4f8585d61ee9d5317bc11039cbaa98
4
- data.tar.gz: f2bd553cd4f075311155154b0c7fef9aad415b3f
2
+ SHA256:
3
+ metadata.gz: be204aa4fc34affdeaeb411e506cc6408a1e96fffb6ef7973dbfbb439f192f58
4
+ data.tar.gz: d8a6a4f096f1250aa072c23c5a06d1151b79dc5b415086119bbb5fdc45b344ab
5
5
  SHA512:
6
- metadata.gz: e52a91a7f9c78b9964650972b09c61a883035903f04e41374e82115d04b6643776f9ff05aebb281a007b7074913c9bfb086328ab6043418bd0df0ec8232ccfc8
7
- data.tar.gz: af137419cbb73cceac9e4283a2558d758b0f4425ac009fe9243780328eb6df1091cdcee776147327fb646630a1832573bdbbd7e14b5a9cac8cb4e30d2f31fa5a
6
+ metadata.gz: '007365028b06ce14abbf77273d7d2dacf5d68ad6b3d394bb4e0ea6122ea7f7d59ee72d1a098fba9ad0a4b05152de787d8df3e273d427d08207370a1f53fb2631'
7
+ data.tar.gz: 880f9b005544f1e6185026d249898f739fefede6e99ea0c39e41adf52bd1891195f41f5a6d6d4713aec04b3983f2854e2ab740aac2ffb682079d39ecb481dd4e
@@ -1,9 +1,12 @@
1
- language: ruby
2
- cache: bundler
3
1
  sudo: false
2
+ language: ruby
4
3
  rvm:
5
- - 2.2.5
6
- - 2.3.1
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
7
+ - 2.7
7
8
  script:
8
9
  - bundle exec rspec spec
9
- - bundle exec rubocop --format=clang
10
+ branches:
11
+ only:
12
+ - master
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
- # Praxis Blueprints [![TravisCI][travis-img-url]][travis-ci-url] [![Coverage Status][coveralls-img-url]][coveralls-url] [![Dependency Status][gemnasium-img-url]][gemnasium-url]
1
+ # Praxis Blueprints [![TravisCI][travis-img-url]][travis-ci-url] [![Coverage Status][coveralls-img-url]][coveralls-url]
2
2
 
3
- [travis-img-url]:https://travis-ci.org/rightscale/praxis-blueprints.svg?branch=master
4
- [travis-ci-url]:https://travis-ci.org/rightscale/praxis-blueprints
5
- [coveralls-img-url]:https://coveralls.io/repos/rightscale/praxis-blueprints/badge.svg?branch=master&service=github
6
- [coveralls-url]:https://coveralls.io/github/rightscale/praxis-blueprints?branch=master
3
+ [//]: # ( COMMENTED OUT UNTIL GEMNASIUM CAN SEE THE REPOS: [![Dependency Status][gemnasium-img-url]][gemnasium-url])
4
+
5
+ [travis-img-url]:https://travis-ci.org/praxis/praxis-blueprints.svg?branch=master
6
+ [travis-ci-url]:https://travis-ci.org/praxis/praxis-blueprints
7
+ [coveralls-img-url]:https://coveralls.io/repos/github/praxis/praxis-blueprints/badge.svg?branch=master
8
+ [coveralls-url]:https://coveralls.io/github/praxis/praxis-blueprints?branch=master
7
9
  [gemnasium-img-url]:https://gemnasium.com/rightscale/praxis-blueprints.svg
8
10
  [gemnasium-url]:https://gemnasium.com/rightscale/praxis-blueprints
9
11
 
10
-
11
12
  Praxis Blueprints is a library that allows for defining a reusable class structures that has a set of typed attributes and a set of views with which to render them. Instantiations of Blueprints resemble ruby Structs which respond to methods of the attribute names. Rendering is format-agnostic in that
12
13
  it results in a structured hash instead of an encoded string. Blueprints can automatically generate object structures that follow the attribute definitions.
13
14
 
@@ -275,7 +275,7 @@ module Praxis
275
275
  end
276
276
  end
277
277
  end
278
-
278
+
279
279
  def initialize(object, decorators = nil)
280
280
  # TODO: decide what sort of type checking (if any) we want to perform here.
281
281
  @object = object
@@ -289,6 +289,12 @@ module Praxis
289
289
  @validating = false
290
290
  end
291
291
 
292
+ # By default we'll use the object identity, to avoid rendering the same object twice
293
+ # Override, if there is a better way cache things up
294
+ def _cache_key
295
+ self.object
296
+ end
297
+
292
298
  # Render the wrapped data with the given view
293
299
  def render(view_name = nil, context: Attributor::DEFAULT_ROOT_CONTEXT, renderer: Renderer.new, **opts)
294
300
  if !view_name.nil?
@@ -317,9 +323,13 @@ module Praxis
317
323
 
318
324
  renderer.render(self, expanded_fields, context: context)
319
325
  end
320
- alias to_hash render
326
+
321
327
  alias dump render
322
328
 
329
+ def to_h
330
+ Attributor.recursive_to_h(@object)
331
+ end
332
+
323
333
  def validate(context = Attributor::DEFAULT_ROOT_CONTEXT)
324
334
  raise ArgumentError, "Invalid context received (nil) while validating value of type #{self.name}" if context.nil?
325
335
  context = [context] if context.is_a? ::String
@@ -47,7 +47,7 @@ module Praxis
47
47
  render(sub_object, sub_fields, view, context: sub_context)
48
48
  end
49
49
  elsif object.is_a? Praxis::Blueprint
50
- @cache[object.object_id][fields.object_id] ||= _render(object, fields, view, context: context)
50
+ @cache[object._cache_key][fields] ||= _render(object, fields, view, context: context)
51
51
  else
52
52
  _render(object, fields, view, context: context)
53
53
  end
@@ -76,7 +76,7 @@ module Praxis
76
76
  begin
77
77
  value = object._get_attr(key)
78
78
  rescue => e
79
- raise Attributor::DumpError, context: context, name: key, type: object.class, original_exception: e
79
+ raise Attributor::DumpError.new(context: context, name: key, type: object.class, original_exception: e)
80
80
  end
81
81
 
82
82
  if value.nil?
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Praxis
3
- BLUEPRINTS_VERSION = '3.3'
3
+ BLUEPRINTS_VERSION = '3.4'
4
4
  end
@@ -35,8 +35,6 @@ module Praxis
35
35
  renderer.render(object, expanded_fields, context: context)
36
36
  end
37
37
 
38
- alias to_hash render # Why did we need this again?
39
-
40
38
  def attribute(name, **opts, &block)
41
39
  raise AttributorException, "Attribute names must be symbols, got: #{name.inspect}" unless name.is_a? ::Symbol
42
40
 
@@ -78,7 +76,7 @@ module Praxis
78
76
  object = schema.example(context)
79
77
  opts = {}
80
78
  opts[:context] = context if context
81
- render(object, opts)
79
+ render(object, **opts)
82
80
  end
83
81
 
84
82
  def describe
@@ -28,21 +28,23 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
 
30
30
  spec.add_runtime_dependency('randexp', ['~> 0'])
31
- spec.add_runtime_dependency('attributor', ['>= 5.1'])
31
+ spec.add_runtime_dependency('attributor', ['>= 5.4'])
32
32
  spec.add_runtime_dependency('activesupport', ['>= 3'])
33
33
 
34
- spec.add_development_dependency 'bundler', '~> 1.6'
35
- spec.add_development_dependency 'rake', '~> 0'
34
+ spec.add_development_dependency 'bundler'
35
+ spec.add_development_dependency 'rake'
36
36
 
37
37
  spec.add_development_dependency('redcarpet', ['< 3.0'])
38
- spec.add_development_dependency('yard', ['~> 0.8.7'])
38
+ spec.add_development_dependency('yard')
39
39
  spec.add_development_dependency('guard', ['~> 2'])
40
40
  spec.add_development_dependency('guard-rspec', ['>= 0'])
41
- spec.add_development_dependency('rspec', ['< 2.99'])
42
- spec.add_development_dependency('pry', ['~> 0'])
43
- spec.add_development_dependency('pry-byebug', ['~> 1'])
44
- spec.add_development_dependency('pry-stack_explorer', ['~> 0'])
45
- spec.add_development_dependency('fuubar', ['~> 1'])
41
+ spec.add_development_dependency('rspec')
42
+ spec.add_development_dependency('rspec-its')
43
+ spec.add_development_dependency('rspec-collection_matchers')
44
+ spec.add_development_dependency('pry')
45
+ spec.add_development_dependency('pry-byebug')
46
+ spec.add_development_dependency('pry-stack_explorer')
47
+ spec.add_development_dependency('fuubar')
46
48
  spec.add_development_dependency('coveralls')
47
49
  spec.add_development_dependency 'rubocop'
48
50
  spec.add_development_dependency 'guard-rubocop'
@@ -102,14 +102,20 @@ describe Praxis::Blueprint do
102
102
 
103
103
  context 'validation' do
104
104
  subject(:errors) { blueprint_class.validate(blueprint_instance) }
105
- pending do
106
- it { should be_empty }
107
- end
105
+ it { should be_empty }
108
106
  end
109
107
  end
110
108
 
111
109
  context 'from Blueprint.example' do
112
- subject(:blueprint_instance) { blueprint_class.example }
110
+ subject(:blueprint_instance) do
111
+ blueprint_class.example('ExamplePerson',
112
+ address: nil,
113
+ prior_addresses: [],
114
+ work_address: nil,
115
+ myself: nil,
116
+ friends: []
117
+ )
118
+ end
113
119
  it_behaves_like 'a blueprint instance'
114
120
  end
115
121
 
@@ -118,7 +124,7 @@ describe Praxis::Blueprint do
118
124
  {
119
125
  name: 'Bob',
120
126
  full_name: FullName.example,
121
- address: Address.example,
127
+ address: nil,
122
128
  email: 'bob@example.com',
123
129
  aliases: [],
124
130
  prior_addresses: [],
@@ -150,7 +150,7 @@ describe Praxis::Renderer do
150
150
 
151
151
  context 'rendering stuff that breaks badly' do
152
152
  it 'does not break badly' do
153
- renderer.render(person, tags: [true])
153
+ renderer.render(person, {tags: [true]})
154
154
  end
155
155
  end
156
156
 
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.3'
4
+ version: '3.4'
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: 2016-08-19 00:00:00.000000000 Z
12
+ date: 2020-05-01 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: '5.1'
34
+ version: '5.4'
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: '5.1'
41
+ version: '5.4'
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: '1.6'
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: '1.6'
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.8.7
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.8.7
111
+ version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: guard
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -141,72 +141,100 @@ 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: '2.99'
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
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
152
166
  - !ruby/object:Gem::Version
153
- version: '2.99'
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: '1'
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: '1'
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: '1'
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: '1'
237
+ version: '0'
210
238
  - !ruby/object:Gem::Dependency
211
239
  name: coveralls
212
240
  requirement: !ruby/object:Gem::Requirement
@@ -311,8 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
339
  - !ruby/object:Gem::Version
312
340
  version: '0'
313
341
  requirements: []
314
- rubyforge_project:
315
- rubygems_version: 2.5.1
342
+ rubygems_version: 3.0.3
316
343
  signing_key:
317
344
  specification_version: 4
318
345
  summary: Attributes, views, rendering and example generation for common Blueprint
@@ -326,4 +353,3 @@ test_files:
326
353
  - spec/praxis-blueprints/view_spec.rb
327
354
  - spec/spec_helper.rb
328
355
  - spec/support/spec_blueprints.rb
329
- has_rdoc: