servactory 2.13.2 → 2.14.0

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: 8d303c7927860fbde7534d718fd64104cce4caad49304636767ef6b0da8f9d3a
4
- data.tar.gz: d8065166611e2da7a40e6529df84e12002e72e8533cd2015bf5ee867f65f3ca8
3
+ metadata.gz: 0f6718e3b5e71152099847ec1713940116c44a7641dbc3c63d7a4ef60478ef3c
4
+ data.tar.gz: 9ecd3809f2792504bb5f2694b4ceb9969e5bd4ad386dccfbdb5af6e0a8e55a9a
5
5
  SHA512:
6
- metadata.gz: f28e93b9cb1932770e44ce8e17d726edef59be66608dd9d68a063d3389db4e71f2cbda685cdbc5081164aa3cb1ff0d6719431078238d0f5053d8f7df97d16e2c
7
- data.tar.gz: f454f6d653fe7f31e039c5f5b5816863edb7399f433beb4b78f5dc31895d7d86200e0bac374528a85e8855bd0370bb53515c643a55e9ce412571dd2222ce11fe
6
+ metadata.gz: 1810233557cfb71509fcf04e618295cde0ab190511b8bb50569cd098cf359c606730de1299d89eaaeec8e6c55d65b901fc7bbea895e46532a1a3f825d5bfcc6f
7
+ data.tar.gz: 4011679f170547c0ee3b4e1c527dfadccb961185446d4386c3a9ff6da81da9a6da683d7d5102ca339a5609c644d61ded644321115cc1697368451301c53a8078
@@ -52,7 +52,15 @@ module ApplicationService
52
52
 
53
53
  # hash_mode_class_names [CustomHash]
54
54
 
55
- # action_shortcuts %i[assign build create save]
55
+ # action_shortcuts(
56
+ # %i[assign build create save],
57
+ # {
58
+ # restrict: {
59
+ # prefix: :create,
60
+ # suffix: :restriction
61
+ # }
62
+ # }
63
+ # )
56
64
 
57
65
  # action_aliases %i[do_it!]
58
66
 
@@ -87,14 +87,16 @@ module Servactory
87
87
  end
88
88
 
89
89
  def method_missing(name, ...)
90
- return method_missing_for_action_aliases(name, ...) if config.action_aliases.include?(name)
90
+ return method_missing_for_action_aliases(...) if config.action_aliases.include?(name)
91
91
 
92
- return method_missing_for_shortcuts_for_make(name, ...) if config.action_shortcuts.include?(name)
92
+ if (action_shortcut = config.action_shortcuts.find_by(name:)).present?
93
+ return method_missing_for_shortcuts_for_make(action_shortcut, ...)
94
+ end
93
95
 
94
96
  super
95
97
  end
96
98
 
97
- def method_missing_for_action_aliases(_alias_name, *args)
99
+ def method_missing_for_action_aliases(*args)
98
100
  method_name = args.first
99
101
  method_options = args.last.is_a?(Hash) ? args.pop : {}
100
102
 
@@ -103,16 +105,37 @@ module Servactory
103
105
  make(method_name, **method_options)
104
106
  end
105
107
 
106
- def method_missing_for_shortcuts_for_make(shortcut_name, *args)
108
+ def method_missing_for_shortcuts_for_make(action_shortcut, *args)
107
109
  method_options = args.last.is_a?(Hash) ? args.pop : {}
108
110
 
109
111
  args.each do |method_name|
110
- make(:"#{shortcut_name}_#{method_name}", **method_options)
112
+ full_method_name = build_method_name_for_shortcuts_for_make_with(
113
+ method_name.to_s,
114
+ action_shortcut
115
+ )
116
+
117
+ make(full_method_name, **method_options)
111
118
  end
112
119
  end
113
120
 
121
+ def build_method_name_for_shortcuts_for_make_with(method_name, action_shortcut)
122
+ prefix = action_shortcut.fetch(:prefix)
123
+ suffix = action_shortcut.fetch(:suffix)
124
+
125
+ method_body, special_char =
126
+ Servactory::Utils.extract_special_character_from(method_name.to_s)
127
+
128
+ parts = []
129
+ parts << "#{prefix}_" if prefix.present?
130
+ parts << method_body
131
+ parts << "_#{suffix}" if suffix.present?
132
+ parts << special_char if special_char
133
+
134
+ parts.join.to_sym
135
+ end
136
+
114
137
  def respond_to_missing?(name, *)
115
- config.action_aliases.include?(name) || config.action_shortcuts.include?(name) || super
138
+ config.action_aliases.include?(name) || config.action_shortcuts.shortcuts.include?(name) || super
116
139
  end
117
140
 
118
141
  def next_position
@@ -6,10 +6,20 @@ module Servactory
6
6
  module Shortcuts
7
7
  class Collection
8
8
  extend Forwardable
9
- def_delegators :@collection, :<<, :each, :merge, :include?
9
+ def_delegators :@collection, :merge!, :fetch, :keys
10
10
 
11
11
  def initialize(*)
12
- @collection = Set.new
12
+ @collection = {}
13
+ end
14
+
15
+ alias merge merge!
16
+
17
+ def shortcuts
18
+ keys
19
+ end
20
+
21
+ def find_by(name:)
22
+ fetch(name, nil)
13
23
  end
14
24
  end
15
25
  end
@@ -5,7 +5,7 @@ module Servactory
5
5
  module CollectionMode
6
6
  class ClassNamesCollection
7
7
  extend Forwardable
8
- def_delegators :@collection, :merge, :intersection
8
+ def_delegators :@collection, :merge, :intersect?
9
9
 
10
10
  def initialize(collection)
11
11
  @collection = collection
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Servactory
4
4
  module Configuration
5
- class Factory
5
+ class Factory # rubocop:disable Metrics/ClassLength
6
6
  def initialize(config)
7
7
  @config = config
8
8
  end
@@ -63,8 +63,20 @@ module Servactory
63
63
  @config.action_aliases.merge(action_aliases)
64
64
  end
65
65
 
66
- def action_shortcuts(action_shortcuts)
67
- @config.action_shortcuts.merge(action_shortcuts)
66
+ def action_shortcuts(array, hash = {}) # rubocop:disable Metrics/MethodLength
67
+ prepared = array.to_h do |action_shortcut|
68
+ [
69
+ action_shortcut,
70
+ {
71
+ prefix: action_shortcut,
72
+ suffix: nil
73
+ }
74
+ ]
75
+ end
76
+
77
+ prepared = prepared.merge(hash)
78
+
79
+ @config.action_shortcuts.merge(prepared)
68
80
  end
69
81
 
70
82
  def i18n_root_key(value)
@@ -5,7 +5,7 @@ module Servactory
5
5
  module HashMode
6
6
  class ClassNamesCollection
7
7
  extend Forwardable
8
- def_delegators :@collection, :include?
8
+ def_delegators :@collection, :include?, :intersect?
9
9
 
10
10
  def initialize(collection)
11
11
  @collection = collection
@@ -129,7 +129,7 @@ module Servactory
129
129
  end
130
130
 
131
131
  def failure_inclusion_passes? # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
132
- input_inclusion_in = attribute_data.fetch(:inclusion, {}).fetch(:in, nil)
132
+ input_inclusion_in = attribute_data.dig(:inclusion, :in)
133
133
 
134
134
  return true if input_inclusion_in.blank?
135
135
 
@@ -28,7 +28,7 @@ module Servactory
28
28
 
29
29
  def common_condition_with(attribute:, value:, option:)
30
30
  return true if option.value == false
31
- return [false, :wrong_type] if @collection_mode_class_names.intersection(attribute.types).empty?
31
+ return [false, :wrong_type] unless @collection_mode_class_names.intersect?(attribute.types)
32
32
 
33
33
  values = value.respond_to?(:flatten) ? value&.flatten : value
34
34
 
@@ -10,14 +10,14 @@ module Servactory
10
10
  end
11
11
 
12
12
  def condition_for_input_with(input:, value:, option:)
13
- if input.required? || (
14
- input.optional? && !input.default.nil?
15
- ) || (
16
- input.optional? && !value.nil?
17
- ) # do
13
+ if input.required? || (input.optional? && !value.nil?) # rubocop:disable Style/IfUnlessModifier
18
14
  return option.value.include?(value)
19
15
  end
20
16
 
17
+ if input.optional? && value.nil? && !input.default.nil? # rubocop:disable Style/IfUnlessModifier
18
+ return option.value.include?(input.default)
19
+ end
20
+
21
21
  true
22
22
  end
23
23
 
@@ -29,9 +29,9 @@ module Servactory
29
29
  common_condition_with(attribute: output, value:, option:)
30
30
  end
31
31
 
32
- def common_condition_with(attribute:, value:, option:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
32
+ def common_condition_with(attribute:, value:, option:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
33
33
  return true if option.value == false
34
- return [false, :wrong_type] if @default_hash_mode_class_names.intersection(attribute.types).empty?
34
+ return [false, :wrong_type] unless @default_hash_mode_class_names.intersect?(attribute.types)
35
35
 
36
36
  if value.blank? && ((attribute.input? && attribute.optional?) || attribute.internal? || attribute.output?)
37
37
  return true
@@ -46,6 +46,14 @@ module Servactory
46
46
  false
47
47
  end
48
48
 
49
+ def extract_special_character_from(string)
50
+ if string.end_with?("!", "?")
51
+ [string.chop, string[-1]]
52
+ else
53
+ [string, nil]
54
+ end
55
+ end
56
+
49
57
  FALSE_VALUES = [
50
58
  false,
51
59
  nil, "",
@@ -3,8 +3,8 @@
3
3
  module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 13
7
- PATCH = 2
6
+ MINOR = 14
7
+ PATCH = 0
8
8
  PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.2
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-19 00:00:00.000000000 Z
10
+ date: 2025-04-21 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -103,14 +103,14 @@ dependencies:
103
103
  name: appraisal
104
104
  requirement: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - "~>"
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '2.5'
109
109
  type: :development
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '2.5'
116
116
  - !ruby/object:Gem::Dependency
@@ -189,14 +189,14 @@ dependencies:
189
189
  requirements:
190
190
  - - ">="
191
191
  - !ruby/object:Gem::Version
192
- version: '0.7'
192
+ version: '0.9'
193
193
  type: :development
194
194
  prerelease: false
195
195
  version_requirements: !ruby/object:Gem::Requirement
196
196
  requirements:
197
197
  - - ">="
198
198
  - !ruby/object:Gem::Version
199
- version: '0.7'
199
+ version: '0.9'
200
200
  - !ruby/object:Gem::Dependency
201
201
  name: steep
202
202
  requirement: !ruby/object:Gem::Requirement
@@ -347,7 +347,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
347
347
  requirements:
348
348
  - - ">="
349
349
  - !ruby/object:Gem::Version
350
- version: 3.1.0
350
+ version: '3.2'
351
351
  required_rubygems_version: !ruby/object:Gem::Requirement
352
352
  requirements:
353
353
  - - ">="