activeinteractor 2.0.0.alpha.4.0.2 → 2.0.0.alpha.4.0.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
2
  SHA256:
3
- metadata.gz: 49a99115eedcdbf3c20a4f9ae7a2689666a112c18242e8df780a1640ec4cbab6
4
- data.tar.gz: f44209f8fcba17ddd81add053d38754fee6103b0d3322b8cad78a4835ecfbd82
3
+ metadata.gz: a5c6408bdcf2d87a8fcb5fd4eb31a6a65c39daa5a142e2dbea309decc731d472
4
+ data.tar.gz: 05d8bf464f5d1c2f55de64357e04d894905277da9a5fc96f44a987eef880cdaa
5
5
  SHA512:
6
- metadata.gz: 19c71ea32681cce8f34838887e07f04d6cac8fa73a20506c52a269faf92c1613446da878fa5e95de3bab57860d1428242da24e68abb3890003a9db0e8a00155d
7
- data.tar.gz: 4379d708f16448046d760f85d3ab30643c380a9be12726e160e9540e20163da2692a1e813c6e439f479954e67aa923f42617e19c8791161244514429cbfa19a5
6
+ metadata.gz: 0d5f4e51c89e4ba941d3a4b4e0c5f62a2dc99188ff95aaa7645025347bce14833c3aaeca7739faf6eb3bc0370f19c108ccee2b2a7b8aafdbc1a64f3875afc3f9
7
+ data.tar.gz: f3ee81c83b88e54469ded7ba7df55e9ba711f7c3bd1ceff398ecbb215615bea850cd18eaec9bd6c79b39a52f8036f4c2073e6b1431e255cd54364fd19e3c0806
data/CHANGELOG.md CHANGED
@@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning].
27
27
 
28
28
  ## [v1.2.0] - 2022-09-08
29
29
 
30
-
30
+ ### Added
31
31
 
32
32
  - `ActiveInteractor::Base.defer_after_callbacks_when_organized`
33
33
  - `ActiveInteractor::Organizer::Base.after_all_perform`
@@ -6,12 +6,11 @@ module ActiveInteractor
6
6
  NO_DEFAULT_VALUE = :__no_default_value__
7
7
  attr_reader :description, :error_messages, :name
8
8
 
9
- def initialize(owner, name, type, description = nil, **options)
10
- @owner = owner
9
+ def initialize(name, type, description = nil, **options)
10
+ parse_options(description, options)
11
+
11
12
  @name = name.to_sym
12
13
  @type_expression = type
13
- @description = description || options[:description]
14
- @options = { required: false, default: NO_DEFAULT_VALUE }.merge(options)
15
14
  @error_messages = []
16
15
  end
17
16
 
@@ -44,6 +43,19 @@ module ActiveInteractor
44
43
 
45
44
  private
46
45
 
46
+ def parse_options(description, options)
47
+ if description.is_a?(String)
48
+ @description = description
49
+ @options = { required: false, default: NO_DEFAULT_VALUE }.merge(options)
50
+ elsif description.is_a?(Hash)
51
+ @options = { required: false, default: NO_DEFAULT_VALUE }.merge(description)
52
+ @description = @options[:description]
53
+ elsif description.nil?
54
+ @description = nil
55
+ @options = { required: false, default: NO_DEFAULT_VALUE }.merge(options)
56
+ end
57
+ end
58
+
47
59
  def type_is_a_active_interactor_type?
48
60
  type.is_a?(ActiveInteractor::Type::Base) || type.superclass == ActiveInteractor::Type::Base
49
61
  end
@@ -55,19 +67,16 @@ module ActiveInteractor
55
67
  end
56
68
 
57
69
  def validate_type!
58
- return true if value.nil?
59
- return true if %i[any untyped].include?(type)
60
-
61
- if type_is_a_active_interactor_type?
62
- return true if type.valid?(value)
63
-
64
- error_messages << :invalid
65
- elsif value.is_a?(type)
66
- return true
67
- end
70
+ return true if value_nil_or_untyped?
71
+ return true if type_is_a_active_interactor_type? && type.valid?(value)
72
+ return true if value.is_a?(type)
68
73
 
69
74
  error_messages << :invalid
70
75
  end
76
+
77
+ def value_nil_or_untyped?
78
+ value.nil? || %i[any untyped].include?(type)
79
+ end
71
80
  end
72
81
  end
73
82
  end
@@ -3,15 +3,14 @@
3
3
  module ActiveInteractor
4
4
  module Context
5
5
  class AttributeSet
6
- def initialize(owner, *attributes)
7
- @owner = owner
6
+ def initialize(*attributes)
8
7
  @set = {}
9
8
  attributes.each { |attribute| @set[attribute.name] = attribute }
10
9
  end
11
10
 
12
11
  def add(*attribute_args)
13
12
  attribute_options = attribute_args.extract_options!
14
- attribute = Attribute.new(@owner, *attribute_args, **attribute_options)
13
+ attribute = Attribute.new(*attribute_args, **attribute_options)
15
14
  @set[attribute.name] = attribute
16
15
  end
17
16
 
@@ -8,6 +8,8 @@ module ActiveInteractor
8
8
  include ActiveModel::Validations
9
9
  include Type::DeclerationMethods
10
10
 
11
+ validate :validate_attributes!
12
+
11
13
  class << self
12
14
  def method_defined?(method_name)
13
15
  attribute_set.attribute_names.include?(method_name.to_s.delete('=').to_sym) || super
@@ -16,7 +18,7 @@ module ActiveInteractor
16
18
  protected
17
19
 
18
20
  def attribute_set
19
- @attribute_set ||= AttributeSet.new(self)
21
+ @attribute_set ||= AttributeSet.new
20
22
  end
21
23
  end
22
24
 
@@ -55,7 +57,7 @@ module ActiveInteractor
55
57
  end
56
58
 
57
59
  def attribute_set
58
- @attribute_set ||= AttributeSet.new(self, *self.class.send(:attribute_set).attributes.map(&:dup))
60
+ @attribute_set ||= AttributeSet.new(*self.class.send(:attribute_set).attributes.map(&:dup))
59
61
  end
60
62
 
61
63
  def method_missing(method_name, *arguments)
@@ -78,6 +80,13 @@ module ActiveInteractor
78
80
 
79
81
  super
80
82
  end
83
+
84
+ def validate_attributes!
85
+ attribute_set.attributes.each do |attribute|
86
+ attribute.validate!
87
+ attribute.error_messages.each { |message| errors.add(attribute.name, message) }
88
+ end
89
+ end
81
90
  end
82
91
  end
83
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeinteractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha.4.0.2
4
+ version: 2.0.0.alpha.4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-12 00:00:00.000000000 Z
11
+ date: 2024-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -66,7 +66,6 @@ files:
66
66
  - lib/active_interactor/context.rb
67
67
  - lib/active_interactor/context/attribute.rb
68
68
  - lib/active_interactor/context/attribute_set.rb
69
- - lib/active_interactor/context/attribute_validation.rb
70
69
  - lib/active_interactor/context/base.rb
71
70
  - lib/active_interactor/context/input.rb
72
71
  - lib/active_interactor/context/output.rb
@@ -89,10 +88,10 @@ licenses:
89
88
  - MIT
90
89
  metadata:
91
90
  bug_tracker_uri: https://github.com/activeinteractor/activeinteractor/issues
92
- changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.4.0.2/CHANGELOG.md
91
+ changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.4.0.4/CHANGELOG.md
93
92
  homepage_uri: https://activeinteractor.org
94
- source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.4.0.2
95
- documentation_uri: https://activeinteractor.org/api/activeinteractor/v2.0.0-alpha.4.0.2
93
+ source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.4.0.4
94
+ documentation_uri: https://activeinteractor.org/api/activeinteractor/v2.0.0-alpha.4.0.4
96
95
  wiki_uri: https://github.com/activeinteractor/activeinteractor/wiki
97
96
  rubygems_mfa_required: 'true'
98
97
  post_install_message:
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveInteractor
4
- module Context
5
- module AttributeValidation
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- validate :validate_attributes!
10
- end
11
-
12
- protected
13
-
14
- def validate_attributes!
15
- attribute_set.attributes.each do |attribute|
16
- attribute.validate!
17
- attribute.error_messages.each { |message| errors.add(attribute.name, message) }
18
- end
19
- end
20
- end
21
- end
22
- end