servactory 3.0.0.rc2 → 3.0.0.rc3
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5972f03405d88ae923f1e000479449e281af67b9d22b52010d2131dc1023cc15
|
|
4
|
+
data.tar.gz: 6c7c495d158deee0453114fb637897a2431d7ce4efc4e522a0716ec28a7dd89b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82e84edd70b3ee47a91944bd60e5d9bec1cf33b18ca5d008d40973685c796cfa31b48de2f0599764c864db535959cd86a073ed30725c1fe1af49a98ce4bd72ab
|
|
7
|
+
data.tar.gz: 585a53ba4491246e5e4aaec23568e074a2d142d467b9d44bc551d629bce2047fcfd99d89c0bdcb897e9a28e9f7037b9128396107fe6c01083ff0b4298ee11f71
|
|
@@ -136,11 +136,7 @@ module Servactory
|
|
|
136
136
|
return if @define_methods.blank?
|
|
137
137
|
|
|
138
138
|
@define_methods.map do |define_method|
|
|
139
|
-
|
|
140
|
-
def #{define_method.name};
|
|
141
|
-
#{define_method.content.call(option: @body)};
|
|
142
|
-
end
|
|
143
|
-
RUBY
|
|
139
|
+
"def #{define_method.name}; #{define_method.content.call(option: @body)}; end"
|
|
144
140
|
end.join("; ")
|
|
145
141
|
end
|
|
146
142
|
end
|
|
@@ -3,19 +3,64 @@
|
|
|
3
3
|
module Servactory
|
|
4
4
|
module Maintenance
|
|
5
5
|
module Attributes
|
|
6
|
+
# Collection wrapper for managing Option objects.
|
|
7
|
+
#
|
|
8
|
+
# ## Purpose
|
|
9
|
+
#
|
|
10
|
+
# OptionsCollection provides a unified interface for storing and querying
|
|
11
|
+
# Option instances associated with service attributes (inputs, internals, outputs).
|
|
12
|
+
# It wraps a Set to ensure uniqueness and delegates common enumeration methods.
|
|
13
|
+
#
|
|
14
|
+
# ## Usage
|
|
15
|
+
#
|
|
16
|
+
# The collection is used internally by Input, Internal, and Output classes
|
|
17
|
+
# to manage their registered options:
|
|
18
|
+
#
|
|
19
|
+
# ```ruby
|
|
20
|
+
# collection = OptionsCollection.new
|
|
21
|
+
# collection << Option.new(name: :required, ...)
|
|
22
|
+
# collection << Option.new(name: :types, ...)
|
|
23
|
+
#
|
|
24
|
+
# collection.names # => [:required, :types]
|
|
25
|
+
# collection.find_by(name: :required) # => Option instance
|
|
26
|
+
# ```
|
|
27
|
+
#
|
|
28
|
+
# ## Performance
|
|
29
|
+
#
|
|
30
|
+
# The collection uses memoization for frequently accessed data:
|
|
31
|
+
# - `validation_classes` - cached list of unique validation classes
|
|
32
|
+
# - `options_for_checks` - cached hash for validation pipeline
|
|
33
|
+
# - `options_index` - cached hash for O(1) lookups by name
|
|
34
|
+
#
|
|
6
35
|
class OptionsCollection
|
|
7
36
|
extend Forwardable
|
|
8
37
|
|
|
9
|
-
def_delegators :@collection,
|
|
38
|
+
def_delegators :@collection,
|
|
39
|
+
:<<,
|
|
40
|
+
:filter,
|
|
41
|
+
:each, :each_with_object,
|
|
42
|
+
:map, :flat_map,
|
|
43
|
+
:find,
|
|
44
|
+
:size,
|
|
45
|
+
:empty?
|
|
10
46
|
|
|
47
|
+
# Initializes an empty collection.
|
|
48
|
+
#
|
|
49
|
+
# @return [OptionsCollection]
|
|
11
50
|
def initialize
|
|
12
51
|
@collection = Set.new
|
|
13
52
|
end
|
|
14
53
|
|
|
54
|
+
# Returns all option names in the collection.
|
|
55
|
+
#
|
|
56
|
+
# @return [Array<Symbol>] list of option names
|
|
15
57
|
def names
|
|
16
58
|
map(&:name)
|
|
17
59
|
end
|
|
18
60
|
|
|
61
|
+
# Returns unique validation classes from all options.
|
|
62
|
+
#
|
|
63
|
+
# @return [Array<Class>] deduplicated list of validation classes
|
|
19
64
|
def validation_classes
|
|
20
65
|
@validation_classes ||=
|
|
21
66
|
filter { |option| option.validation_class.present? }
|
|
@@ -23,24 +68,47 @@ module Servactory
|
|
|
23
68
|
.uniq
|
|
24
69
|
end
|
|
25
70
|
|
|
71
|
+
# Returns options that need validation checks as a hash.
|
|
72
|
+
#
|
|
73
|
+
# @return [Hash{Symbol => Object}] option names mapped to normalized bodies
|
|
26
74
|
def options_for_checks
|
|
27
|
-
filter(&:need_for_checks?).to_h do |option|
|
|
75
|
+
@options_for_checks ||= filter(&:need_for_checks?).to_h do |option|
|
|
28
76
|
[option.name, extract_normalized_body_from(option:)]
|
|
29
77
|
end
|
|
30
78
|
end
|
|
31
79
|
|
|
80
|
+
# Returns the first conflict code found among options.
|
|
81
|
+
#
|
|
82
|
+
# @return [Object, nil] conflict code or nil if no conflicts
|
|
32
83
|
def defined_conflict_code
|
|
33
84
|
flat_map { |option| resolve_conflicts_from(option:) }
|
|
34
85
|
.reject(&:blank?)
|
|
35
86
|
.first
|
|
36
87
|
end
|
|
37
88
|
|
|
89
|
+
# Finds an option by its name using indexed lookup.
|
|
90
|
+
#
|
|
91
|
+
# @param name [Symbol] the option name to find
|
|
92
|
+
# @return [Option, nil] the found option or nil
|
|
38
93
|
def find_by(name:)
|
|
39
|
-
|
|
94
|
+
options_index[name]
|
|
40
95
|
end
|
|
41
96
|
|
|
42
97
|
private
|
|
43
98
|
|
|
99
|
+
# Builds and caches a hash index for O(1) option lookups.
|
|
100
|
+
#
|
|
101
|
+
# @return [Hash{Symbol => Option}] option names mapped to Option instances
|
|
102
|
+
def options_index
|
|
103
|
+
@options_index ||= each_with_object({}) do |option, index|
|
|
104
|
+
index[option.name] = option
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Extracts the normalized body value from an option.
|
|
109
|
+
#
|
|
110
|
+
# @param option [Option] the option to extract from
|
|
111
|
+
# @return [Object] the :is value if body is a Hash with :is key, otherwise the full body
|
|
44
112
|
def extract_normalized_body_from(option:)
|
|
45
113
|
body = option.body
|
|
46
114
|
return body unless body.is_a?(Hash)
|
|
@@ -48,6 +116,10 @@ module Servactory
|
|
|
48
116
|
body.key?(:is) ? body.fetch(:is) : body
|
|
49
117
|
end
|
|
50
118
|
|
|
119
|
+
# Resolves conflict codes from an option's define_conflicts.
|
|
120
|
+
#
|
|
121
|
+
# @param option [Option] the option to check for conflicts
|
|
122
|
+
# @return [Array<Object>] array of conflict codes (may contain nils/blanks)
|
|
51
123
|
def resolve_conflicts_from(option:)
|
|
52
124
|
return [] unless option.define_conflicts
|
|
53
125
|
|
data/lib/servactory/version.rb
CHANGED