activeinteractor 2.0.0.alpha.2.2.0 → 2.0.0.alpha.2.3.1
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/lib/active_interactor/base.rb +2 -0
- data/lib/active_interactor/context/attribute.rb +27 -2
- data/lib/active_interactor/context/attribute_assignment.rb +8 -0
- data/lib/active_interactor/context/base.rb +2 -7
- data/lib/active_interactor/has_active_model_errors.rb +4 -4
- data/lib/active_interactor/result.rb +1 -1
- data/lib/active_interactor/type/base.rb +9 -0
- data/lib/active_interactor/type/boolean.rb +14 -0
- data/lib/active_interactor/type/has_types.rb +34 -0
- data/lib/active_interactor/type/list.rb +29 -0
- data/lib/active_interactor/type/union.rb +27 -0
- data/lib/active_interactor/type.rb +13 -0
- data/lib/active_interactor.rb +1 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8af4270754db50c59e2c28fd5877446d12e1d15617ff8ce2dc67b97a0a95830
|
4
|
+
data.tar.gz: 43d1b328973b54ef6623db8e216a2d5a6d84098582ccb674e998ae181b88171a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a9e727d815c173b8be85a47cf65110a48e5e3e65bf370764a29d12060f5da85e2b4a444f35e87c15e4c328795834f3e315a351993deb46fad1d8e7432b78a06
|
7
|
+
data.tar.gz: 655d2a8362d581afb7074b8b00abbd97e496071bb5ce373dd4f475c04e881dc5a8406d4ecd95d7921c29d5e2346aaac7b6f532f54a2c7b31223f5dee38a4ab9f
|
@@ -34,13 +34,38 @@ module ActiveInteractor
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def validate!
|
37
|
+
validate_presence! && validate_type!
|
38
|
+
end
|
39
|
+
|
40
|
+
def value
|
41
|
+
@user_provided_value || default_value
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def type_is_a_active_interactor_type?
|
47
|
+
type.is_a?(ActiveInteractor::Type::Base) || type.superclass == ActiveInteractor::Type::Base
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_presence!
|
37
51
|
return true unless required? && value.nil?
|
38
52
|
|
39
53
|
error_messages << :blank
|
40
54
|
end
|
41
55
|
|
42
|
-
def
|
43
|
-
|
56
|
+
def validate_type!
|
57
|
+
return true if value.nil?
|
58
|
+
return true if %i[any untyped].include?(type)
|
59
|
+
|
60
|
+
if type_is_a_active_interactor_type?
|
61
|
+
return true if type.valid?(value)
|
62
|
+
|
63
|
+
error_messages << :invalid
|
64
|
+
elsif value.is_a?(type)
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
|
68
|
+
error_messages << :invalid
|
44
69
|
end
|
45
70
|
end
|
46
71
|
end
|
@@ -5,6 +5,14 @@ module ActiveInteractor
|
|
5
5
|
module AttributeAssignment
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
def initialize(attributes = {})
|
9
|
+
attribute_set.attributes.each do |attribute|
|
10
|
+
next unless attributes.with_indifferent_access.key?(attribute.name)
|
11
|
+
|
12
|
+
assign_attribute_value(attribute.name, attributes.with_indifferent_access[attribute.name])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
8
16
|
def [](attribute_name)
|
9
17
|
read_attribute_value(attribute_name)
|
10
18
|
end
|
@@ -7,16 +7,11 @@ module ActiveInteractor
|
|
7
7
|
include HasActiveModelErrors
|
8
8
|
include AttributeRegistration
|
9
9
|
include AttributeAssignment
|
10
|
-
|
11
|
-
attr_reader :errors
|
10
|
+
include Type::HasTypes
|
12
11
|
|
13
12
|
def initialize(attributes = {})
|
13
|
+
super
|
14
14
|
@errors = ActiveModel::Errors.new(self)
|
15
|
-
attribute_set.attributes.each do |attribute|
|
16
|
-
next unless attributes.with_indifferent_access.key?(attribute.name)
|
17
|
-
|
18
|
-
assign_attribute_value(attribute.name, attributes.with_indifferent_access[attribute.name])
|
19
|
-
end
|
20
15
|
end
|
21
16
|
|
22
17
|
def validate!
|
@@ -4,12 +4,14 @@ module ActiveInteractor
|
|
4
4
|
module HasActiveModelErrors
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
+
attr_reader :errors
|
8
|
+
|
7
9
|
module ClassMethods
|
8
|
-
def
|
10
|
+
def human_attribute_name(attribute, _options = {})
|
9
11
|
attribute.respond_to?(:to_s) ? attribute.to_s.humanize : attribute
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
14
|
+
def lookup_ancestors
|
13
15
|
[self]
|
14
16
|
end
|
15
17
|
end
|
@@ -17,8 +19,6 @@ module ActiveInteractor
|
|
17
19
|
included do
|
18
20
|
extend ActiveModel::Naming
|
19
21
|
extend ClassMethods
|
20
|
-
|
21
|
-
attr_reader :errors
|
22
22
|
end
|
23
23
|
|
24
24
|
def read_attribute_for_validation(attribute_name)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveInteractor
|
4
|
+
module Type
|
5
|
+
class Boolean < Base
|
6
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON', 'yes', 'YES'].freeze
|
7
|
+
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', 'no', 'NO'].freeze
|
8
|
+
|
9
|
+
def self.valid?(value)
|
10
|
+
(TRUE_VALUES + FALSE_VALUES).include?(value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveInteractor
|
4
|
+
module Type
|
5
|
+
module HasTypes
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
Boolean = ActiveInteractor::Type::Boolean
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def any
|
12
|
+
:any
|
13
|
+
end
|
14
|
+
|
15
|
+
def list(type)
|
16
|
+
List.new(type)
|
17
|
+
end
|
18
|
+
alias array list
|
19
|
+
|
20
|
+
def union(*types)
|
21
|
+
Union.new(*types)
|
22
|
+
end
|
23
|
+
|
24
|
+
def untyped
|
25
|
+
:untyped
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
included do
|
30
|
+
extend ClassMethods
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveInteractor
|
4
|
+
module Type
|
5
|
+
class List < Base
|
6
|
+
def initialize(type) # rubocop:disable Lint/MissingSuper
|
7
|
+
@type = type
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid?(value)
|
11
|
+
return false unless value.is_a?(Array)
|
12
|
+
|
13
|
+
value.all? do |element|
|
14
|
+
element.nil? || element.is_a?(@type) || (@type.is_a?(ActiveInteractor::Type::Base) && @type.valid?(element))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def value_is_a_valid_active_interactor_type?(_type, value)
|
21
|
+
unless @type.is_a?(ActiveInteractor::Type::Base) || @type.superclass == ActiveInteractor::Type::Base
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
@type.valid?(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveInteractor
|
4
|
+
module Type
|
5
|
+
class Union < Base
|
6
|
+
def initialize(*types) # rubocop:disable Lint/MissingSuper
|
7
|
+
@valid_types = types
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid?(value)
|
11
|
+
return true if value.nil?
|
12
|
+
|
13
|
+
@valid_types.any? do |type|
|
14
|
+
value_is_a_valid_active_interactor_type?(type, value) || value.is_a?(type)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def value_is_a_valid_active_interactor_type?(type, value)
|
21
|
+
return false unless type.is_a?(ActiveInteractor::Type::Base) || type.superclass == ActiveInteractor::Type::Base
|
22
|
+
|
23
|
+
type.valid?(value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/active_interactor.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeinteractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.alpha.2.
|
4
|
+
version: 2.0.0.alpha.2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Allen
|
@@ -76,15 +76,21 @@ files:
|
|
76
76
|
- lib/active_interactor/errors.rb
|
77
77
|
- lib/active_interactor/has_active_model_errors.rb
|
78
78
|
- lib/active_interactor/result.rb
|
79
|
+
- lib/active_interactor/type.rb
|
80
|
+
- lib/active_interactor/type/base.rb
|
81
|
+
- lib/active_interactor/type/boolean.rb
|
82
|
+
- lib/active_interactor/type/has_types.rb
|
83
|
+
- lib/active_interactor/type/list.rb
|
84
|
+
- lib/active_interactor/type/union.rb
|
79
85
|
- sig/active_interactor.rbs
|
80
86
|
homepage: https://github.com/activeinteractor/activeinteractor
|
81
87
|
licenses:
|
82
88
|
- MIT
|
83
89
|
metadata:
|
84
90
|
bug_tracker_uri: https://github.com/activeinteractor/activeinteractor/issues
|
85
|
-
changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.2.
|
91
|
+
changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.2.3.1/CHANGELOG.md
|
86
92
|
homepage_uri: https://github.com/activeinteractor/activeinteractor
|
87
|
-
source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.2.
|
93
|
+
source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.2.3.1
|
88
94
|
wiki_uri: https://github.com/activeinteractor/activeinteractor/wiki
|
89
95
|
rubygems_mfa_required: 'true'
|
90
96
|
post_install_message:
|
@@ -102,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
108
|
- !ruby/object:Gem::Version
|
103
109
|
version: 1.3.1
|
104
110
|
requirements: []
|
105
|
-
rubygems_version: 3.4.
|
111
|
+
rubygems_version: 3.4.20
|
106
112
|
signing_key:
|
107
113
|
specification_version: 4
|
108
114
|
summary: Ruby interactors with ActiveModel::Validations
|