spicerack 0.25.8 → 0.26.0.3
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/spicerack.rb +10 -8
- data/lib/spicerack/spec_helper.rb +1 -4
- data/lib/spicerack/version.rb +1 -1
- metadata +46 -37
- data/lib/spicerack/attribute_object.rb +0 -11
- data/lib/spicerack/input_model.rb +0 -12
- data/lib/spicerack/input_object.rb +0 -24
- data/lib/spicerack/objects/arguments.rb +0 -38
- data/lib/spicerack/objects/attributes.rb +0 -39
- data/lib/spicerack/objects/defaults.rb +0 -40
- data/lib/spicerack/objects/options.rb +0 -37
- data/lib/spicerack/objects/output.rb +0 -63
- data/lib/spicerack/objects/status.rb +0 -21
- data/lib/spicerack/output_object.rb +0 -11
- data/lib/spicerack/root_object.rb +0 -24
- data/lib/spicerack/rspec/custom_matchers.rb +0 -6
- data/lib/spicerack/rspec/custom_matchers/define_argument.rb +0 -29
- data/lib/spicerack/rspec/custom_matchers/define_attribute.rb +0 -21
- data/lib/spicerack/rspec/custom_matchers/define_field.rb +0 -43
- data/lib/spicerack/rspec/custom_matchers/define_option.rb +0 -34
- data/lib/spicerack/rspec/shared_examples.rb +0 -3
- data/lib/spicerack/rspec/shared_examples/an_input_object_with_a_class_collection_attribute.rb +0 -63
- data/lib/spicerack/rspec/shoulda_matcher_helper.rb +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 546ee6c890ec2b885ba4684c0e9fcc00903e78c1f31107a6de80e9552c093961
|
|
4
|
+
data.tar.gz: 648e8860885c803a483305db6a9c816d5ae0aca04b92505b3e99c849f062ea90
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '089bf3b9d51b749efc1ad1738701e9faabc336e9865cf85e04117de638654006becc7c37e4f44115261cabdb1a735935090ec16ce164b1aa1f0a436659039bf4'
|
|
7
|
+
data.tar.gz: 6d4142b22881259bbcbb6da0b8acab4dfdd8b2240156a24876fe8125802dcd9120e9280920ab11b729365ff791d24c8f606f08e094d36264ed1e893289ed8fda
|
data/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
This collection of gems will spice up your rails and kick your rubies up a notch. Bam!
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/rb/spicerack)
|
|
6
|
-
[](https://semaphoreci.com/freshly/spicerack)
|
|
7
7
|
[](https://codeclimate.com/github/Freshly/spicerack/maintainability)
|
|
8
8
|
[](https://codeclimate.com/github/Freshly/spicerack/test_coverage)
|
|
9
9
|
|
|
@@ -106,7 +106,7 @@ Then in the base directory:
|
|
|
106
106
|
|
|
107
107
|
Next, push the code up and open a new pull request.
|
|
108
108
|
|
|
109
|
-
Once that gets merged into
|
|
109
|
+
Once that gets merged into main, run:
|
|
110
110
|
|
|
111
111
|
- Run `rake spicerack:release_all` to claim the new gem name with the empty build
|
|
112
112
|
|
|
@@ -129,7 +129,7 @@ rake spicerack:release_all
|
|
|
129
129
|
|
|
130
130
|
This will build and release all dependent gems at the same time.
|
|
131
131
|
|
|
132
|
-
Only the
|
|
132
|
+
Only the `main` branch should be released!
|
|
133
133
|
|
|
134
134
|
### Versions
|
|
135
135
|
|
data/lib/spicerack.rb
CHANGED
|
@@ -6,10 +6,10 @@ require "active_support/core_ext/object/inclusion"
|
|
|
6
6
|
|
|
7
7
|
require "spicerack/version"
|
|
8
8
|
|
|
9
|
-
require "tablesalt"
|
|
10
|
-
|
|
11
9
|
require "around_the_world"
|
|
12
10
|
require "short_circu_it"
|
|
11
|
+
require "substance"
|
|
12
|
+
require "tablesalt"
|
|
13
13
|
require "technologic"
|
|
14
14
|
|
|
15
15
|
require "redis_hash"
|
|
@@ -17,13 +17,15 @@ require "redis_hash"
|
|
|
17
17
|
require "spicerack/array_index"
|
|
18
18
|
require "spicerack/hash_model"
|
|
19
19
|
require "spicerack/redis_model"
|
|
20
|
-
require "spicerack/root_object"
|
|
21
|
-
require "spicerack/attribute_object"
|
|
22
|
-
require "spicerack/input_object"
|
|
23
|
-
require "spicerack/input_model"
|
|
24
|
-
require "spicerack/output_object"
|
|
25
20
|
|
|
26
21
|
module Spicerack
|
|
27
22
|
class Error < StandardError; end
|
|
28
|
-
|
|
23
|
+
|
|
24
|
+
include ActiveSupport::Deprecation::DeprecatedConstantAccessor
|
|
25
|
+
|
|
26
|
+
deprecate_constant "RootObject", "Substance::RootObject"
|
|
27
|
+
deprecate_constant "AttributeObject", "Substance::AttributeObject"
|
|
28
|
+
deprecate_constant "InputModel", "Substance::InputModel"
|
|
29
|
+
deprecate_constant "InputObject", "Substance::InputObject"
|
|
30
|
+
deprecate_constant "OutputObject", "Substance::OutputObject"
|
|
29
31
|
end
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require "rspice"
|
|
4
4
|
require "redis_hash/spec_helper"
|
|
5
|
+
require "substance/rspec"
|
|
5
6
|
require "technologic/spec_helper"
|
|
6
7
|
require "tablesalt/spec_helper"
|
|
7
|
-
|
|
8
|
-
require_relative "rspec/custom_matchers"
|
|
9
|
-
require_relative "rspec/shared_examples"
|
|
10
|
-
require_relative "rspec/shoulda_matcher_helper"
|
data/lib/spicerack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spicerack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.26.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Garside
|
|
@@ -12,7 +12,7 @@ authors:
|
|
|
12
12
|
autorequire:
|
|
13
13
|
bindir: bin
|
|
14
14
|
cert_chain: []
|
|
15
|
-
date: 2021-04
|
|
15
|
+
date: 2021-05-04 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: around_the_world
|
|
@@ -20,70 +20,98 @@ dependencies:
|
|
|
20
20
|
requirements:
|
|
21
21
|
- - '='
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
|
-
version: 0.
|
|
23
|
+
version: 0.26.0.3
|
|
24
24
|
type: :runtime
|
|
25
25
|
prerelease: false
|
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
|
27
27
|
requirements:
|
|
28
28
|
- - '='
|
|
29
29
|
- !ruby/object:Gem::Version
|
|
30
|
-
version: 0.
|
|
30
|
+
version: 0.26.0.3
|
|
31
|
+
- !ruby/object:Gem::Dependency
|
|
32
|
+
name: directive
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - '='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 0.26.0.3
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - '='
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: 0.26.0.3
|
|
31
45
|
- !ruby/object:Gem::Dependency
|
|
32
46
|
name: redis_hash
|
|
33
47
|
requirement: !ruby/object:Gem::Requirement
|
|
34
48
|
requirements:
|
|
35
49
|
- - '='
|
|
36
50
|
- !ruby/object:Gem::Version
|
|
37
|
-
version: 0.
|
|
51
|
+
version: 0.26.0.3
|
|
38
52
|
type: :runtime
|
|
39
53
|
prerelease: false
|
|
40
54
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
55
|
requirements:
|
|
42
56
|
- - '='
|
|
43
57
|
- !ruby/object:Gem::Version
|
|
44
|
-
version: 0.
|
|
58
|
+
version: 0.26.0.3
|
|
45
59
|
- !ruby/object:Gem::Dependency
|
|
46
60
|
name: short_circu_it
|
|
47
61
|
requirement: !ruby/object:Gem::Requirement
|
|
48
62
|
requirements:
|
|
49
63
|
- - '='
|
|
50
64
|
- !ruby/object:Gem::Version
|
|
51
|
-
version: 0.
|
|
65
|
+
version: 0.26.0.3
|
|
66
|
+
type: :runtime
|
|
67
|
+
prerelease: false
|
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - '='
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: 0.26.0.3
|
|
73
|
+
- !ruby/object:Gem::Dependency
|
|
74
|
+
name: substance
|
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - '='
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: 0.26.0.3
|
|
52
80
|
type: :runtime
|
|
53
81
|
prerelease: false
|
|
54
82
|
version_requirements: !ruby/object:Gem::Requirement
|
|
55
83
|
requirements:
|
|
56
84
|
- - '='
|
|
57
85
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: 0.
|
|
86
|
+
version: 0.26.0.3
|
|
59
87
|
- !ruby/object:Gem::Dependency
|
|
60
88
|
name: technologic
|
|
61
89
|
requirement: !ruby/object:Gem::Requirement
|
|
62
90
|
requirements:
|
|
63
91
|
- - '='
|
|
64
92
|
- !ruby/object:Gem::Version
|
|
65
|
-
version: 0.
|
|
93
|
+
version: 0.26.0.3
|
|
66
94
|
type: :runtime
|
|
67
95
|
prerelease: false
|
|
68
96
|
version_requirements: !ruby/object:Gem::Requirement
|
|
69
97
|
requirements:
|
|
70
98
|
- - '='
|
|
71
99
|
- !ruby/object:Gem::Version
|
|
72
|
-
version: 0.
|
|
100
|
+
version: 0.26.0.3
|
|
73
101
|
- !ruby/object:Gem::Dependency
|
|
74
102
|
name: tablesalt
|
|
75
103
|
requirement: !ruby/object:Gem::Requirement
|
|
76
104
|
requirements:
|
|
77
105
|
- - '='
|
|
78
106
|
- !ruby/object:Gem::Version
|
|
79
|
-
version: 0.
|
|
107
|
+
version: 0.26.0.3
|
|
80
108
|
type: :runtime
|
|
81
109
|
prerelease: false
|
|
82
110
|
version_requirements: !ruby/object:Gem::Requirement
|
|
83
111
|
requirements:
|
|
84
112
|
- - '='
|
|
85
113
|
- !ruby/object:Gem::Version
|
|
86
|
-
version: 0.
|
|
114
|
+
version: 0.26.0.3
|
|
87
115
|
- !ruby/object:Gem::Dependency
|
|
88
116
|
name: bundler
|
|
89
117
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -208,28 +236,28 @@ dependencies:
|
|
|
208
236
|
requirements:
|
|
209
237
|
- - '='
|
|
210
238
|
- !ruby/object:Gem::Version
|
|
211
|
-
version: 0.
|
|
239
|
+
version: 0.26.0.3
|
|
212
240
|
type: :development
|
|
213
241
|
prerelease: false
|
|
214
242
|
version_requirements: !ruby/object:Gem::Requirement
|
|
215
243
|
requirements:
|
|
216
244
|
- - '='
|
|
217
245
|
- !ruby/object:Gem::Version
|
|
218
|
-
version: 0.
|
|
246
|
+
version: 0.26.0.3
|
|
219
247
|
- !ruby/object:Gem::Dependency
|
|
220
248
|
name: spicerack-styleguide
|
|
221
249
|
requirement: !ruby/object:Gem::Requirement
|
|
222
250
|
requirements:
|
|
223
251
|
- - '='
|
|
224
252
|
- !ruby/object:Gem::Version
|
|
225
|
-
version: 0.
|
|
253
|
+
version: 0.26.0.3
|
|
226
254
|
type: :development
|
|
227
255
|
prerelease: false
|
|
228
256
|
version_requirements: !ruby/object:Gem::Requirement
|
|
229
257
|
requirements:
|
|
230
258
|
- - '='
|
|
231
259
|
- !ruby/object:Gem::Version
|
|
232
|
-
version: 0.
|
|
260
|
+
version: 0.26.0.3
|
|
233
261
|
- !ruby/object:Gem::Dependency
|
|
234
262
|
name: will_paginate
|
|
235
263
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -294,27 +322,8 @@ files:
|
|
|
294
322
|
- README.md
|
|
295
323
|
- lib/spicerack.rb
|
|
296
324
|
- lib/spicerack/array_index.rb
|
|
297
|
-
- lib/spicerack/attribute_object.rb
|
|
298
325
|
- lib/spicerack/hash_model.rb
|
|
299
|
-
- lib/spicerack/input_model.rb
|
|
300
|
-
- lib/spicerack/input_object.rb
|
|
301
|
-
- lib/spicerack/objects/arguments.rb
|
|
302
|
-
- lib/spicerack/objects/attributes.rb
|
|
303
|
-
- lib/spicerack/objects/defaults.rb
|
|
304
|
-
- lib/spicerack/objects/options.rb
|
|
305
|
-
- lib/spicerack/objects/output.rb
|
|
306
|
-
- lib/spicerack/objects/status.rb
|
|
307
|
-
- lib/spicerack/output_object.rb
|
|
308
326
|
- lib/spicerack/redis_model.rb
|
|
309
|
-
- lib/spicerack/root_object.rb
|
|
310
|
-
- lib/spicerack/rspec/custom_matchers.rb
|
|
311
|
-
- lib/spicerack/rspec/custom_matchers/define_argument.rb
|
|
312
|
-
- lib/spicerack/rspec/custom_matchers/define_attribute.rb
|
|
313
|
-
- lib/spicerack/rspec/custom_matchers/define_field.rb
|
|
314
|
-
- lib/spicerack/rspec/custom_matchers/define_option.rb
|
|
315
|
-
- lib/spicerack/rspec/shared_examples.rb
|
|
316
|
-
- lib/spicerack/rspec/shared_examples/an_input_object_with_a_class_collection_attribute.rb
|
|
317
|
-
- lib/spicerack/rspec/shoulda_matcher_helper.rb
|
|
318
327
|
- lib/spicerack/spec_helper.rb
|
|
319
328
|
- lib/spicerack/version.rb
|
|
320
329
|
homepage: https://github.com/Freshly/spicerack
|
|
@@ -323,7 +332,7 @@ licenses:
|
|
|
323
332
|
metadata:
|
|
324
333
|
homepage_uri: https://github.com/Freshly/spicerack
|
|
325
334
|
source_code_uri: https://github.com/Freshly/spicerack
|
|
326
|
-
changelog_uri: https://github.com/Freshly/spicerack/blob/
|
|
335
|
+
changelog_uri: https://github.com/Freshly/spicerack/blob/main/CHANGELOG.md
|
|
327
336
|
documentation_uri: https://www.rubydoc.info/gems/spicerack
|
|
328
337
|
post_install_message:
|
|
329
338
|
rdoc_options: []
|
|
@@ -340,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
340
349
|
- !ruby/object:Gem::Version
|
|
341
350
|
version: '0'
|
|
342
351
|
requirements: []
|
|
343
|
-
rubygems_version: 3.1.
|
|
352
|
+
rubygems_version: 3.1.6
|
|
344
353
|
signing_key:
|
|
345
354
|
specification_version: 4
|
|
346
355
|
summary: A suite of utility gems for Ruby on Rails.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "objects/defaults"
|
|
4
|
-
require_relative "objects/attributes"
|
|
5
|
-
|
|
6
|
-
module Spicerack
|
|
7
|
-
class AttributeObject < Spicerack::RootObject
|
|
8
|
-
include Spicerack::Objects::Defaults
|
|
9
|
-
include Spicerack::Objects::Attributes
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Spicerack
|
|
4
|
-
class InputModel < InputObject
|
|
5
|
-
extend ActiveModel::Naming
|
|
6
|
-
extend ActiveModel::Translation
|
|
7
|
-
|
|
8
|
-
include ActiveModel::Conversion
|
|
9
|
-
include ActiveModel::Validations
|
|
10
|
-
include ActiveModel::Validations::Callbacks
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "objects/arguments"
|
|
4
|
-
require_relative "objects/options"
|
|
5
|
-
|
|
6
|
-
module Spicerack
|
|
7
|
-
class InputObject < Spicerack::AttributeObject
|
|
8
|
-
define_callbacks :initialize
|
|
9
|
-
|
|
10
|
-
include Spicerack::Objects::Arguments
|
|
11
|
-
include Spicerack::Objects::Options
|
|
12
|
-
|
|
13
|
-
def initialize(**input)
|
|
14
|
-
@input = input
|
|
15
|
-
run_callbacks(:initialize) do
|
|
16
|
-
input.each { |key, value| __send__("#{key}=".to_sym, value) }
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
attr_reader :input
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Arguments describe input that is required (which can be nil, unless otherwise specified).
|
|
4
|
-
module Spicerack
|
|
5
|
-
module Objects
|
|
6
|
-
module Arguments
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
|
|
9
|
-
included do
|
|
10
|
-
class_attribute :_arguments, instance_writer: false, default: {}
|
|
11
|
-
set_callback :initialize, :after do
|
|
12
|
-
missing_arguments = _arguments.reject do |argument, options|
|
|
13
|
-
options[:allow_nil] ? input.key?(argument) : !input[argument].nil?
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
missing = missing_arguments.keys
|
|
17
|
-
|
|
18
|
-
raise ArgumentError, "Missing #{"argument".pluralize(missing.length)}: #{missing.join(", ")}" if missing.any?
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class_methods do
|
|
23
|
-
def inherited(base)
|
|
24
|
-
dup = _arguments.dup
|
|
25
|
-
base._arguments = dup.each { |k, v| dup[k] = v.dup }
|
|
26
|
-
super
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def argument(argument, allow_nil: true)
|
|
32
|
-
_arguments[argument] = { allow_nil: allow_nil }
|
|
33
|
-
define_attribute argument
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Attributes are structured data within an object.
|
|
4
|
-
module Spicerack
|
|
5
|
-
module Objects
|
|
6
|
-
module Attributes
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
|
|
9
|
-
included do
|
|
10
|
-
class_attribute :_attributes, instance_writer: false, default: []
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class_methods do
|
|
14
|
-
def inherited(base)
|
|
15
|
-
base._attributes = _attributes.dup
|
|
16
|
-
super
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def define_attribute(attribute)
|
|
22
|
-
_attributes << attribute
|
|
23
|
-
attr_accessor attribute
|
|
24
|
-
end
|
|
25
|
-
alias_method :attribute, :define_attribute
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def to_h
|
|
29
|
-
_attributes.each_with_object({}) { |attr, hash| hash[attr] = public_send(attr) }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def stringable_attributes
|
|
35
|
-
self.class._attributes
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Defaults are used as the value when then attribute is unspecified.
|
|
4
|
-
module Spicerack
|
|
5
|
-
module Objects
|
|
6
|
-
module Defaults
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
|
|
9
|
-
included do
|
|
10
|
-
class_attribute :_defaults, instance_writer: false, default: {}
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class_methods do
|
|
14
|
-
def inherited(base)
|
|
15
|
-
dup = _defaults.dup
|
|
16
|
-
base._defaults = dup.each { |k, v| dup[k] = v.dup }
|
|
17
|
-
super
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def define_default(attribute, static: nil, &block)
|
|
23
|
-
_defaults[attribute] = Value.new(static: static, &block)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Value
|
|
28
|
-
include Tablesalt::Isolation
|
|
29
|
-
|
|
30
|
-
def initialize(static: nil, &block)
|
|
31
|
-
@value = (static.nil? && block_given?) ? block : static
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def value
|
|
35
|
-
isolate(@value.respond_to?(:call) ? instance_eval(&@value) : @value)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Options describe input which may be provided to define or override default values.
|
|
4
|
-
module Spicerack
|
|
5
|
-
module Objects
|
|
6
|
-
module Options
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
|
|
9
|
-
included do
|
|
10
|
-
class_attribute :_options, instance_writer: false, default: []
|
|
11
|
-
|
|
12
|
-
set_callback :initialize, :after do
|
|
13
|
-
_options.each do |option|
|
|
14
|
-
next unless _defaults.key?(option)
|
|
15
|
-
|
|
16
|
-
public_send("#{option}=".to_sym, _defaults[option].value) if public_send(option).nil?
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class_methods do
|
|
22
|
-
def inherited(base)
|
|
23
|
-
base._options = _options.dup
|
|
24
|
-
super
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def option(option, default: nil, &block)
|
|
30
|
-
_options << option
|
|
31
|
-
define_attribute option
|
|
32
|
-
define_default option, static: default, &block
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Spicerack
|
|
4
|
-
module Objects
|
|
5
|
-
module Output
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
included do
|
|
9
|
-
class_attribute :_outputs, instance_writer: false, default: []
|
|
10
|
-
|
|
11
|
-
delegate :_outputs, to: :class
|
|
12
|
-
|
|
13
|
-
after_validation do
|
|
14
|
-
next unless validated?
|
|
15
|
-
|
|
16
|
-
_outputs.each do |key|
|
|
17
|
-
public_send("#{key}=".to_sym, _defaults[key].value) if _defaults.key?(key) && public_send(key).nil?
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class_methods do
|
|
23
|
-
def inherited(base)
|
|
24
|
-
base._outputs = _outputs.dup
|
|
25
|
-
super
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def output(output, default: nil, &block)
|
|
31
|
-
_outputs << output
|
|
32
|
-
define_attribute output
|
|
33
|
-
define_default output, static: default, &block
|
|
34
|
-
ensure_validation_before output
|
|
35
|
-
ensure_validation_before "#{output}=".to_sym
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def ensure_validation_before(method)
|
|
39
|
-
around_method method do |*args, **opts|
|
|
40
|
-
raise NotValidatedError unless validated?
|
|
41
|
-
|
|
42
|
-
# TODO: replace with `super(...)` when <= 2.6 support is dropped
|
|
43
|
-
if RUBY_VERSION < "2.7" && opts.blank?
|
|
44
|
-
super(*args)
|
|
45
|
-
else
|
|
46
|
-
super(*args, **opts)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def outputs
|
|
53
|
-
return {} if _outputs.empty?
|
|
54
|
-
|
|
55
|
-
output_struct.new(*_outputs.map(&method(:public_send)))
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def output_struct
|
|
59
|
-
Struct.new(*_outputs)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Spicerack
|
|
4
|
-
module Objects
|
|
5
|
-
module Status
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
included do
|
|
9
|
-
after_validation { self.was_validated = errors.empty? }
|
|
10
|
-
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
attr_accessor :was_validated
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def validated?
|
|
17
|
-
was_validated.present?
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Spicerack
|
|
4
|
-
class RootObject
|
|
5
|
-
include ActiveSupport::Callbacks
|
|
6
|
-
include ShortCircuIt
|
|
7
|
-
include Technologic
|
|
8
|
-
include Tablesalt::StringableObject
|
|
9
|
-
|
|
10
|
-
class << self
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
def define_callbacks_with_handler(*events, handler: :on, filter: :after)
|
|
14
|
-
define_callbacks(*events)
|
|
15
|
-
|
|
16
|
-
events.each do |event|
|
|
17
|
-
define_singleton_method("#{handler}_#{event}".to_sym) do |*filters, &block|
|
|
18
|
-
set_callback(event, filter, *filters, &block)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# RSpec matcher that tests usage of `.argument`
|
|
4
|
-
#
|
|
5
|
-
# class Example < Spicerack::InputObject
|
|
6
|
-
# argument :foo
|
|
7
|
-
# argument :bar, allow_nil: false
|
|
8
|
-
# end
|
|
9
|
-
#
|
|
10
|
-
# RSpec.describe Example, type: :input_object do
|
|
11
|
-
# subject { described_class.new(**input) }
|
|
12
|
-
#
|
|
13
|
-
# let(:input) { {} }
|
|
14
|
-
#
|
|
15
|
-
# it { is_expected.to define_argument :foo }
|
|
16
|
-
# it { is_expected.to define_argument :bar, allow_nil: false }
|
|
17
|
-
# end
|
|
18
|
-
|
|
19
|
-
RSpec::Matchers.define :define_argument do |argument, allow_nil: true|
|
|
20
|
-
match { |instance| expect(instance._arguments[argument]).to eq(allow_nil: allow_nil) }
|
|
21
|
-
description { "define argument #{argument}" }
|
|
22
|
-
failure_message do
|
|
23
|
-
"expected #{described_class} to define argument #{argument} #{prohibit_nil_description unless allow_nil}"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def prohibit_nil_description
|
|
27
|
-
"and prohibit a nil value"
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# RSpec matcher that tests usage of `.attribute`
|
|
4
|
-
#
|
|
5
|
-
# class Example < Spicerack::InputObject
|
|
6
|
-
# attribute :foo
|
|
7
|
-
# end
|
|
8
|
-
#
|
|
9
|
-
# RSpec.describe Example, type: :input_object do
|
|
10
|
-
# subject { described_class.new(**input) }
|
|
11
|
-
#
|
|
12
|
-
# let(:input) { {} }
|
|
13
|
-
#
|
|
14
|
-
# it { is_expected.to define_attribute :foo }
|
|
15
|
-
# end
|
|
16
|
-
|
|
17
|
-
RSpec::Matchers.define :define_attribute do |attribute|
|
|
18
|
-
match { |instance| expect(instance._attributes).to include attribute }
|
|
19
|
-
description { "define attribute #{attribute}" }
|
|
20
|
-
failure_message { "expected #{described_class} to defines attribute #{attribute}" }
|
|
21
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# RSpec matcher that tests usage of `.field`
|
|
4
|
-
#
|
|
5
|
-
# class Example < Spicerack::HashModel
|
|
6
|
-
# field :foo, :datetime
|
|
7
|
-
# field :bar, :integer
|
|
8
|
-
# end
|
|
9
|
-
#
|
|
10
|
-
# RSpec.describe Example, type: :hash_model do
|
|
11
|
-
# subject { described_class.new.tap { |model| model.data = data } }
|
|
12
|
-
#
|
|
13
|
-
# let(:data) { {} }
|
|
14
|
-
#
|
|
15
|
-
# it { is_expected.to define_field :foo, :datetime }
|
|
16
|
-
# it { is_expected.to define_field :bar, :integer }
|
|
17
|
-
# end
|
|
18
|
-
|
|
19
|
-
RSpec::Matchers.define :define_field do |field, type = nil, default: nil|
|
|
20
|
-
match do
|
|
21
|
-
expect(test_subject.attribute_types[field.to_s].type).to eq type unless type.nil?
|
|
22
|
-
expect(test_subject._default_attributes[field.to_s].value).to eq default unless default.nil?
|
|
23
|
-
expect(test_subject._fields).to include field.to_s
|
|
24
|
-
end
|
|
25
|
-
description { "define field #{field}" }
|
|
26
|
-
failure_message { "expected #{test_subject} to define field #{field} #{with_details(type, default)}" }
|
|
27
|
-
|
|
28
|
-
def with_details(type, default)
|
|
29
|
-
[ with_type(type), with_default(default) ].compact.join(" ")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def with_type(type)
|
|
33
|
-
"of type #{type}" unless type.nil?
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def with_default(default)
|
|
37
|
-
"with default #{default}" unless default.nil?
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_subject
|
|
41
|
-
subject.is_a?(Class) ? subject : subject.class
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# RSpec matcher that tests usage of `.option`
|
|
4
|
-
#
|
|
5
|
-
# class Example < Spicerack::InputObject
|
|
6
|
-
# option :foo
|
|
7
|
-
# option :bar, default: :baz
|
|
8
|
-
# option(:gaz) { :haz }
|
|
9
|
-
# end
|
|
10
|
-
#
|
|
11
|
-
# RSpec.describe Example, type: :input_object do
|
|
12
|
-
# subject { described_class.new(**input) }
|
|
13
|
-
#
|
|
14
|
-
# let(:input) { {} }
|
|
15
|
-
#
|
|
16
|
-
# it { is_expected.to define_option :foo }
|
|
17
|
-
# it { is_expected.to define_option :bar, default: :baz }
|
|
18
|
-
# it { is_expected.to define_option :gaz, default: :haz }
|
|
19
|
-
# end
|
|
20
|
-
|
|
21
|
-
RSpec::Matchers.define :define_option do |option, default: nil|
|
|
22
|
-
match do |instance|
|
|
23
|
-
expect(instance._defaults[option]&.value).to eq default
|
|
24
|
-
expect(instance._options).to include option
|
|
25
|
-
end
|
|
26
|
-
description { "define option #{option}" }
|
|
27
|
-
failure_message { "expected #{described_class} to define option #{option} #{for_default(default)}" }
|
|
28
|
-
|
|
29
|
-
def for_default(default)
|
|
30
|
-
return "without a default value" if default.nil?
|
|
31
|
-
|
|
32
|
-
"with default value #{default}"
|
|
33
|
-
end
|
|
34
|
-
end
|
data/lib/spicerack/rspec/shared_examples/an_input_object_with_a_class_collection_attribute.rb
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.shared_examples_for "an input object with a class collection attribute" do |method, collection|
|
|
4
|
-
subject(:define) { example_input_object_class.__send__(method, value) }
|
|
5
|
-
|
|
6
|
-
let(:value) { Faker::Lorem.word.to_sym }
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
allow(example_input_object_class).to receive(:define_default).and_call_original
|
|
10
|
-
allow(example_input_object_class).to receive(:define_attribute).and_call_original
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "defines value" do
|
|
14
|
-
let(:default) { Faker::Lorem.word }
|
|
15
|
-
|
|
16
|
-
shared_examples_for "an value is defined" do
|
|
17
|
-
it "adds to _values" do
|
|
18
|
-
expect { define }.to change { example_input_object_class.public_send(collection) }.from([]).to([ value ])
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context "when no block is given" do
|
|
23
|
-
subject(:define) { example_input_object_class.__send__(method, value, default: default) }
|
|
24
|
-
|
|
25
|
-
it_behaves_like "an value is defined"
|
|
26
|
-
|
|
27
|
-
it "defines an static default" do
|
|
28
|
-
define
|
|
29
|
-
expect(example_input_object_class).to have_received(:define_default).with(value, static: default)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "when a block is given" do
|
|
34
|
-
subject(:define) { example_input_object_class.__send__(method, value, default: default, &block) }
|
|
35
|
-
|
|
36
|
-
let(:block) do
|
|
37
|
-
->(_) { :block }
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
shared_examples_for "values are handed off to define_default" do
|
|
41
|
-
it "calls define_default" do
|
|
42
|
-
define
|
|
43
|
-
expect(example_input_object_class).to have_received(:define_default).with(value, static: default, &block)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context "with a static default" do
|
|
48
|
-
it_behaves_like "values are handed off to define_default"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context "without a static default" do
|
|
52
|
-
let(:default) { nil }
|
|
53
|
-
|
|
54
|
-
it_behaves_like "values are handed off to define_default"
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "defines an attribute" do
|
|
60
|
-
define
|
|
61
|
-
expect(example_input_object_class).to have_received(:define_attribute).with(value)
|
|
62
|
-
end
|
|
63
|
-
end
|