servactory 2.13.3 → 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: 686b37992728c9a55817ad99143cb5920e3534229c61f6d4064815b5f5a29195
4
- data.tar.gz: e03438b07981f0c9a9f553c147b52fec9bc51aa78351c8df01ba2e884c758daf
3
+ metadata.gz: 0f6718e3b5e71152099847ec1713940116c44a7641dbc3c63d7a4ef60478ef3c
4
+ data.tar.gz: 9ecd3809f2792504bb5f2694b4ceb9969e5bd4ad386dccfbdb5af6e0a8e55a9a
5
5
  SHA512:
6
- metadata.gz: 7f9c8d95aacf741f565cedd5a56e543b50fbf45427f68a94bf9229e58a5fa029acc0b0fb4ce6391fb3a84e44a248d2c590c4c0c62e080ef8d47f1c8bb51aa851
7
- data.tar.gz: bd2234547c977824d2ae7cf9440e60b575441d31558bc3ac5c0dfea46a4be18957cd68b2ffd83615bcc64909a15be284d798a50e39d97e2821fabccab0bc3586
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
 
@@ -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 = 3
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.3
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-04-02 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
@@ -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'
350
+ version: '3.2'
351
351
  required_rubygems_version: !ruby/object:Gem::Requirement
352
352
  requirements:
353
353
  - - ">="