servactory 1.8.0 → 1.8.1

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: 1a4b777f0ef9ef743ab9af34ced8c2170a96585ecbb4fc6fdb290c07afc05ebf
4
+ data.tar.gz: 01e57d03342d0aa21bd4d49782dcbf9107ae94be2f2761511845313023bf6865
5
5
  SHA512:
6
- metadata.gz: f57071853afa1e92822161608af16e9d303b03bdbe769110cb27d9e59be3d77b4517da5b55d8fdc93a86bcfd470617d5094d8ea03eeb5dd5abad342ead7ae1e9
7
- data.tar.gz: ff862da58716ac985651f59d74aa49f44d06b10c6d8e000bc45877575f83062567f97e0acbaaa9559091ba888ec3a0dde38d9db571f400726a2c9a06a13d042e
6
+ metadata.gz: af1bd571ef3ad8941778c32fde6cd76eafcc8afc01f2966a2517b05d2dfcd51cdd108b6c0168af019e56094d98eaa3d75a530c85874eedcb6aeeb5aacda7e823
7
+ data.tar.gz: cafe7ad733b25bf2bf1e27ee8809a6f659c127fbd4bdb0ae9bffdb9240e9d2671b6217867442834351461f0a6ace6435a4bc9d42bd2b0e0ad31ff93d4bf232c1
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).
@@ -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
@@ -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 = 1
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.1
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-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport