spicerack 0.20.2 → 0.20.3

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
2
  SHA256:
3
- metadata.gz: 3ede6cf7d4b503aa6c1a2e6f75c9821f5026c2045e37bdd24a5ed55a168215f2
4
- data.tar.gz: 5d8493df017b357f8761d232f9567d16d5ab3c7478c60db1f7157631fd97e930
3
+ metadata.gz: 445f354d4e51daa0d30fd70e2d673480f3088c6b6bca5ffdec6ebb6e8943ae9f
4
+ data.tar.gz: 8ed71fe41cf8a7e878cac22d76f630bfdb3c299bfa1610ddd7d4890e8b9ec926
5
5
  SHA512:
6
- metadata.gz: 33525f751e9e08f0e4c4b5d81b1b2c9a11b288eda3e2d514ba1421de1f33d756ee4e3d8cc4cbe09cf2a44821cba1ba2f998954824d1f317112da7c5cfe7de90e
7
- data.tar.gz: 97e87a208851a7917d8a28a08b690875fafe49f89d5c7968de6d762ac2b68f0d1a165bb89f2d226116c7135d8280d64957ec68d6b01a99429ece51cef98abf3e
6
+ metadata.gz: 6fbff23449a89a652361c62255cc5963f928cd5b5e6ee472862e3a1157f3efa5382de9d35b3cc9e5c182f27216035dc02dcee6709abdc7e55702d412ef064ccb
7
+ data.tar.gz: 863491ad5f298561b1ad7182c874d032f41af15575b1c0373132aeac1218c554631ce1a9b23a6f673b999a4c924c6fa55429115badc3fc99e1caf0ca03f182c8
@@ -22,5 +22,6 @@ require "spicerack/attribute_object"
22
22
  require "spicerack/input_object"
23
23
  require "spicerack/input_model"
24
24
  require "spicerack/configurable"
25
+ require "spicerack/stateful_object"
25
26
 
26
27
  module Spicerack; end
@@ -27,7 +27,7 @@ module Spicerack
27
27
 
28
28
  puts <<~WARNING
29
29
  #{self.class._configurable_module_name}.configure has been called more than once, which can lead to unexpected consequences.
30
- For the most predictable behavior, configure should only be called once per library.
30
+ For the most predictable behavior, configure should only be called once.
31
31
  WARNING
32
32
  end
33
33
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spicerack
4
- class InputModel < Spicerack::InputObject
4
+ class InputModel < InputObject
5
5
  extend ActiveModel::Naming
6
6
  extend ActiveModel::Translation
7
7
 
@@ -25,6 +25,10 @@ module Spicerack
25
25
  alias_method :attribute, :define_attribute
26
26
  end
27
27
 
28
+ def to_h
29
+ _attributes.each_with_object({}) { |attr, hash| hash[attr] = public_send(attr) }
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def stringable_attributes
@@ -0,0 +1,58 @@
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 |*arguments|
40
+ raise Flow::State::Errors::NotValidated unless validated?
41
+
42
+ super(*arguments)
43
+ end
44
+ end
45
+ end
46
+
47
+ def outputs
48
+ return {} if _outputs.empty?
49
+
50
+ output_struct.new(*_outputs.map(&method(:public_send)))
51
+ end
52
+
53
+ def output_struct
54
+ Struct.new(*_outputs)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -21,8 +21,8 @@ module Spicerack
21
21
  # it { is_expected.to define_config_option :bar, default: :baz }
22
22
  # end
23
23
  define :define_config_option do |option, default: nil|
24
- description { "define config option #{option}" }
25
- failure_message { "expected #{@obj} to define config option #{option} #{with_default(default)}".strip }
24
+ description { "define config option #{option.inspect}" }
25
+ failure_message { "expected #{@obj} to define config option #{option.inspect} with default #{default.inspect}" }
26
26
 
27
27
  match do |obj|
28
28
  @obj = obj
@@ -35,10 +35,6 @@ module Spicerack
35
35
  expect(obj.config.instance_variable_get(:@config)).to define_option option, default: default
36
36
  end
37
37
  end
38
-
39
- def with_default(default)
40
- "with default #{default}" unless default.nil?
41
- end
42
38
  end
43
39
  end
44
40
  end
@@ -4,6 +4,7 @@ require "rspice"
4
4
  require "redis_hash/spec_helper"
5
5
  require "technologic/spec_helper"
6
6
  require "tablesalt/spec_helper"
7
+ require "conjunction/spec_helper"
7
8
 
8
9
  require_relative "rspec/custom_matchers"
9
10
  require_relative "rspec/shared_examples"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "objects/output"
4
+
5
+ module Spicerack
6
+ class StatefulObject < InputModel
7
+ include Objects::Output
8
+ end
9
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Spicerack
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.20.2"
5
+ VERSION = "0.20.3"
6
6
  end
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.20.2
4
+ version: 0.20.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-01-06 00:00:00.000000000 Z
14
+ date: 2020-01-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: around_the_world
@@ -19,70 +19,70 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.20.2
22
+ version: 0.20.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.20.2
29
+ version: 0.20.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: redis_hash
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - '='
35
35
  - !ruby/object:Gem::Version
36
- version: 0.20.2
36
+ version: 0.20.3
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - '='
42
42
  - !ruby/object:Gem::Version
43
- version: 0.20.2
43
+ version: 0.20.3
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: short_circu_it
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - '='
49
49
  - !ruby/object:Gem::Version
50
- version: 0.20.2
50
+ version: 0.20.3
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - '='
56
56
  - !ruby/object:Gem::Version
57
- version: 0.20.2
57
+ version: 0.20.3
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: technologic
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - '='
63
63
  - !ruby/object:Gem::Version
64
- version: 0.20.2
64
+ version: 0.20.3
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - '='
70
70
  - !ruby/object:Gem::Version
71
- version: 0.20.2
71
+ version: 0.20.3
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: tablesalt
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - '='
77
77
  - !ruby/object:Gem::Version
78
- version: 0.20.2
78
+ version: 0.20.3
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - '='
84
84
  - !ruby/object:Gem::Version
85
- version: 0.20.2
85
+ version: 0.20.3
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: bundler
88
88
  requirement: !ruby/object:Gem::Requirement
@@ -207,28 +207,28 @@ dependencies:
207
207
  requirements:
208
208
  - - '='
209
209
  - !ruby/object:Gem::Version
210
- version: 0.20.2
210
+ version: 0.20.3
211
211
  type: :development
212
212
  prerelease: false
213
213
  version_requirements: !ruby/object:Gem::Requirement
214
214
  requirements:
215
215
  - - '='
216
216
  - !ruby/object:Gem::Version
217
- version: 0.20.2
217
+ version: 0.20.3
218
218
  - !ruby/object:Gem::Dependency
219
219
  name: spicerack-styleguide
220
220
  requirement: !ruby/object:Gem::Requirement
221
221
  requirements:
222
222
  - - '='
223
223
  - !ruby/object:Gem::Version
224
- version: 0.20.2
224
+ version: 0.20.3
225
225
  type: :development
226
226
  prerelease: false
227
227
  version_requirements: !ruby/object:Gem::Requirement
228
228
  requirements:
229
229
  - - '='
230
230
  - !ruby/object:Gem::Version
231
- version: 0.20.2
231
+ version: 0.20.3
232
232
  - !ruby/object:Gem::Dependency
233
233
  name: will_paginate
234
234
  requirement: !ruby/object:Gem::Requirement
@@ -307,6 +307,7 @@ files:
307
307
  - lib/spicerack/objects/attributes.rb
308
308
  - lib/spicerack/objects/defaults.rb
309
309
  - lib/spicerack/objects/options.rb
310
+ - lib/spicerack/objects/output.rb
310
311
  - lib/spicerack/redis_model.rb
311
312
  - lib/spicerack/root_object.rb
312
313
  - lib/spicerack/rspec/configurable/dsl.rb
@@ -323,6 +324,7 @@ files:
323
324
  - lib/spicerack/rspec/shared_examples/an_input_object_with_a_class_collection_attribute.rb
324
325
  - lib/spicerack/rspec/shoulda_matcher_helper.rb
325
326
  - lib/spicerack/spec_helper.rb
327
+ - lib/spicerack/stateful_object.rb
326
328
  - lib/spicerack/version.rb
327
329
  homepage: https://github.com/Freshly/spicerack
328
330
  licenses:
@@ -347,7 +349,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
349
  - !ruby/object:Gem::Version
348
350
  version: '0'
349
351
  requirements: []
350
- rubygems_version: 3.0.3
352
+ rubyforge_project:
353
+ rubygems_version: 2.7.6
351
354
  signing_key:
352
355
  specification_version: 4
353
356
  summary: A suite of utility gems for Ruby on Rails.