servactory 1.8.0 → 1.8.2

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: ddbffa6de1db943a943b369efceef704bb98c5160b13fcada0515069705af423
4
- data.tar.gz: 4b6c33e2d95002a784468ee064ff83d90ce63e01f1ca323dc1afccad103c5063
3
+ metadata.gz: 2a87d01c5389b8d6d538b2cd1befe0cd8fa51b0ea578eefb8c0c0b457957fa75
4
+ data.tar.gz: 4ff7989cf58492790ad7cfef807cd2a2f6befacefa9407a4fb04e3b4567e2d6f
5
5
  SHA512:
6
- metadata.gz: f57071853afa1e92822161608af16e9d303b03bdbe769110cb27d9e59be3d77b4517da5b55d8fdc93a86bcfd470617d5094d8ea03eeb5dd5abad342ead7ae1e9
7
- data.tar.gz: ff862da58716ac985651f59d74aa49f44d06b10c6d8e000bc45877575f83062567f97e0acbaaa9559091ba888ec3a0dde38d9db571f400726a2c9a06a13d042e
6
+ metadata.gz: 2b880c2475447311de03023601adc91597b38ecd083d5e108e4df8869dd65137d2a4001066142234c609c69aecf279d211be2258f806d662fc43893e97fea978
7
+ data.tar.gz: 8efc74ceb569789340dad5b3e1d54cc996528fda101f6bbf9719b9c8f55fc70baf5674659116d27312cc271ec9a7e0764f4de4c9e8a26d674377c157cc1a3330
data/README.md CHANGED
@@ -9,12 +9,18 @@ A set of tools for building reliable services of any complexity.
9
9
 
10
10
  See [servactory.com](https://servactory.com) for documentation.
11
11
 
12
- ## Examples
12
+ ## Example
13
+
14
+ ### Installation
15
+
16
+ ```ruby
17
+ gem "servactory"
18
+ ```
13
19
 
14
20
  ### Service
15
21
 
16
22
  ```ruby
17
- class UserService::Authenticate < ApplicationService::Base
23
+ class UserService::Authenticate < Servactory::Base
18
24
  input :email, type: String
19
25
  input :password, type: String
20
26
 
@@ -32,7 +38,7 @@ class UserService::Authenticate < ApplicationService::Base
32
38
  end
33
39
  ```
34
40
 
35
- ### Using in controller
41
+ ### Usage
36
42
 
37
43
  ```ruby
38
44
  class SessionsController < ApplicationController
@@ -58,8 +64,10 @@ end
58
64
 
59
65
  ## Contributing
60
66
 
61
- This project is intended to be a safe, welcoming space for collaboration. Contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. We recommend reading the [contributing guide](./website/docs/CONTRIBUTING.md) as well.
67
+ This project is intended to be a safe, welcoming space for collaboration.
68
+ Contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
69
+ We recommend reading the [contributing guide](./website/docs/CONTRIBUTING.md) as well.
62
70
 
63
71
  ## License
64
72
 
65
- ViewComponent is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+ Servactory is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -28,7 +28,9 @@ module Servactory
28
28
 
29
29
  return yield unless @collection_of_internals.names.include?(prepared_name)
30
30
 
31
- internal = @collection_of_internals.find_by(name: prepared_name)
31
+ internal = @collection_of_internals.find_by(name: prepared_name) # ::Servactory::Internals::Internal
32
+
33
+ return yield if internal.nil?
32
34
 
33
35
  Servactory::Internals::Validations::Type.validate!(
34
36
  context: @context,
@@ -28,7 +28,9 @@ module Servactory
28
28
 
29
29
  return yield unless @collection_of_outputs.names.include?(prepared_name)
30
30
 
31
- output = @collection_of_outputs.find_by(name: prepared_name)
31
+ output = @collection_of_outputs.find_by(name: prepared_name) # ::Servactory::Outputs::Output
32
+
33
+ return yield if output.nil?
32
34
 
33
35
  Servactory::Outputs::Validations::Type.validate!(
34
36
  context: @context,
@@ -24,14 +24,20 @@ module Servactory
24
24
  options = apply_helpers_for_options(helpers: helpers, options: options) if helpers.present?
25
25
 
26
26
  add_basic_options_with(type: type, options: options)
27
+ end
28
+ # rubocop:enable Style/KeywordParametersOrder
27
29
 
28
- collection_of_options.each do |option|
29
- self.class.attr_reader(:"#{option.name}")
30
+ def method_missing(name, *args, &block)
31
+ option = collection_of_options.find_by(name: name)
30
32
 
31
- instance_variable_set(:"@#{option.name}", option.value)
32
- end
33
+ return super if option.nil?
34
+
35
+ option.value
36
+ end
37
+
38
+ def respond_to_missing?(name, *)
39
+ collection_of_options.names.include?(name) || super
33
40
  end
34
- # rubocop:enable Style/KeywordParametersOrder
35
41
 
36
42
  def apply_helpers_for_options(helpers:, options:)
37
43
  prepared_options = {}
@@ -5,12 +5,16 @@ module Servactory
5
5
  class OptionsCollection
6
6
  # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
7
  extend Forwardable
8
- def_delegators :@collection, :<<, :filter, :each, :map, :flat_map
8
+ def_delegators :@collection, :<<, :filter, :each, :map, :flat_map, :find
9
9
 
10
10
  def initialize(*)
11
11
  @collection = Set.new
12
12
  end
13
13
 
14
+ def names
15
+ map(&:name)
16
+ end
17
+
14
18
  def validation_classes
15
19
  filter { |option| option.validation_class.present? }.map(&:validation_class).uniq
16
20
  end
@@ -34,6 +38,10 @@ module Servactory
34
38
  end
35
39
  end.reject(&:blank?).first
36
40
  end
41
+
42
+ def find_by(name:)
43
+ find { |option| option.name == name }
44
+ end
37
45
  end
38
46
  end
39
47
  end
@@ -87,8 +87,8 @@ module Servactory
87
87
  end
88
88
  end
89
89
 
90
- def respond_to_missing?(shortcut_name, *)
91
- Servactory.configuration.aliases_for_make.include?(shortcut_name) ||
90
+ def respond_to_missing?(name, *)
91
+ Servactory.configuration.aliases_for_make.include?(name) ||
92
92
  Servactory.configuration.shortcuts_for_make.include?(name) ||
93
93
  super
94
94
  end
@@ -3,26 +3,46 @@
3
3
  module Servactory
4
4
  class Result
5
5
  def self.success_for(...)
6
- new.send(:success_for, ...)
6
+ new(...).send(:as_success)
7
7
  end
8
8
 
9
9
  def self.failure_for(...)
10
- new.send(:failure_for, ...)
10
+ new(...).send(:as_failure)
11
11
  end
12
12
 
13
- private
13
+ def initialize(context: nil, collection_of_outputs: nil, exception: nil)
14
+ @context = context
15
+ @collection_of_outputs = collection_of_outputs
16
+ @exception = exception
17
+ end
18
+
19
+ def method_missing(name, *args, &block)
20
+ output = @collection_of_outputs&.find_by(name: name)
21
+
22
+ return super if output.nil?
23
+
24
+ output_value_for(output)
25
+ end
14
26
 
15
- def success_for(context:, collection_of_outputs:)
16
- prepare_outputs_with(context: context, collection_of_outputs: collection_of_outputs)
27
+ def respond_to_missing?(name, *)
28
+ @collection_of_outputs&.names&.include?(name) || super
29
+ end
30
+
31
+ def inspect
32
+ "#<#{self.class.name} #{draw_result}>"
33
+ end
17
34
 
35
+ private
36
+
37
+ def as_success
18
38
  define_singleton_method(:success?) { true }
19
39
  define_singleton_method(:failure?) { false }
20
40
 
21
41
  self
22
42
  end
23
43
 
24
- def failure_for(exception:)
25
- define_singleton_method(:error) { exception }
44
+ def as_failure
45
+ define_singleton_method(:error) { @exception }
26
46
 
27
47
  define_singleton_method(:success?) { false }
28
48
  define_singleton_method(:failure?) { true }
@@ -30,12 +50,14 @@ module Servactory
30
50
  self
31
51
  end
32
52
 
33
- def prepare_outputs_with(context:, collection_of_outputs:)
34
- collection_of_outputs.each do |output|
35
- self.class.attr_reader(:"#{output.name}")
53
+ def draw_result
54
+ @collection_of_outputs&.map do |output|
55
+ "@#{output.name}=#{output_value_for(output).inspect}"
56
+ end&.join(", ")
57
+ end
36
58
 
37
- instance_variable_set(:"@#{output.name}", context.instance_variable_get(:"@#{output.name}"))
38
- end
59
+ def output_value_for(output)
60
+ @context.instance_variable_get(:"@#{output.name}")
39
61
  end
40
62
  end
41
63
  end
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 8
7
- PATCH = 0
7
+ PATCH = 2
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-20 00:00:00.000000000 Z
11
+ date: 2023-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '13.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rbs
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.1'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '3.1'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rspec
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +150,20 @@ dependencies:
164
150
  - - "~>"
165
151
  - !ruby/object:Gem::Version
166
152
  version: '2.19'
153
+ - !ruby/object:Gem::Dependency
154
+ name: steep
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.4'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.4'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement