servactory 2.0.0 → 2.0.2

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: 7f2faba7bb024470613b92cccd026889f07744afa108b02308995332850bcf87
4
- data.tar.gz: c6cd5f199e95e2c104b65778125017a62347e216e97d0cf2f2337fb081fc85ba
3
+ metadata.gz: 1c804a894a51f06d11d05d6b60e539d2d1540959312330726010327dab9a40ed
4
+ data.tar.gz: ab85a273c813f528a596d79efe571d3916f694b1daff5d556d652f28dcab2c98
5
5
  SHA512:
6
- metadata.gz: a46461312794bbee6b5a38b164377a5fb10fd258315936b89f6118f489b4fa66b3b8e75c518a7cc1e32d2827c10844f085d7fa38123eb8c2781177fcdced77fd
7
- data.tar.gz: cf285f17d88fa7034b349b0e22c3bf6649fce0d525a75d49ac22a692a75cd2048e2894065a3e4d83a2241abfafc7fc65390fc690b7d716d54e96d97dd825734e
6
+ metadata.gz: a47f20f6976c843de99822ae9b7cd0ba17a9fc59e0d940776f8a2fe66f9145668507ba4bddb21c8a994994eab765d49f0ee656156aa4394e69c768ec831eff60
7
+ data.tar.gz: 8141c47cd8912dccc02c354cb8c8fa9026238b4c4867de25e1f32c2998aaaf2eb6e4c0ff35e765fced2d585b99f0e458993ac9dfa473674cc07007d2b2ea4033
@@ -68,14 +68,14 @@ module Servactory
68
68
  end
69
69
 
70
70
  def method_missing(name, *args, &block)
71
- return method_missing_for_aliases_for_make(name, *args, &block) if config.action_aliases.include?(name)
71
+ return method_missing_for_action_aliases(name, *args, &block) if config.action_aliases.include?(name)
72
72
 
73
73
  return method_missing_for_shortcuts_for_make(name, *args, &block) if config.action_shortcuts.include?(name)
74
74
 
75
75
  super
76
76
  end
77
77
 
78
- def method_missing_for_aliases_for_make(_alias_name, *args, &block) # rubocop:disable Lint/UnusedMethodArgument
78
+ def method_missing_for_action_aliases(_alias_name, *args, &block) # rubocop:disable Lint/UnusedMethodArgument
79
79
  method_name = args.first
80
80
  method_options = args.last.is_a?(Hash) ? args.pop : {}
81
81
 
@@ -40,7 +40,8 @@ module Servactory
40
40
 
41
41
  private
42
42
 
43
- def getter_with(name:, &block) # rubocop:disable Metrics/MethodLength, Lint/UnusedMethodArgument, Metrics/AbcSize
43
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
44
+ def getter_with(name:, &block)
44
45
  input_name = name.to_s.chomp("?").to_sym
45
46
  input = @collection_of_inputs.find_by(name: input_name)
46
47
 
@@ -61,6 +62,7 @@ module Servactory
61
62
  input.value
62
63
  end
63
64
  end
65
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
64
66
 
65
67
  def prepare_hash_values_inside(object:, schema:) # rubocop:disable Metrics/MethodLength
66
68
  return object unless object.respond_to?(:fetch)
@@ -10,10 +10,10 @@ module Servactory
10
10
  new(...).validate
11
11
  end
12
12
 
13
- def initialize(value:, types:, type:)
14
- @value = value
13
+ def initialize(attribute:, types:, value:)
14
+ @attribute = attribute
15
15
  @types = types
16
- @type = type
16
+ @value = value
17
17
 
18
18
  @errors = []
19
19
  end
@@ -39,21 +39,41 @@ module Servactory
39
39
 
40
40
  private
41
41
 
42
+ def validate_value!
43
+ return if unnecessary_types.empty?
44
+
45
+ add_error(
46
+ expected_type: attribute_consists_of_types.join(", "),
47
+ given_type: unnecessary_types.join(", ")
48
+ )
49
+ end
50
+
51
+ ########################################################################
52
+
42
53
  def prepared_type
43
54
  @prepared_type ||= @types.fetch(0, Array)
44
55
  end
45
56
 
46
- def validate_value!
47
- @value.each do |value_item|
48
- next if value_item.is_a?(@type)
57
+ def attribute_consists_of_types
58
+ @attribute_consists_of_types ||= prepared_types_from(Array(@attribute.consists_of.fetch(:type, [])))
59
+ end
49
60
 
50
- add_error(
51
- expected_type: @type,
52
- given_type: value_item.class.name
53
- )
61
+ def unnecessary_types
62
+ @unnecessary_types ||= @value&.map(&:class)&.difference(attribute_consists_of_types).presence || []
63
+ end
64
+
65
+ def prepared_types_from(types)
66
+ types.map do |type|
67
+ if type.is_a?(String)
68
+ Object.const_get(type)
69
+ else
70
+ type
71
+ end
54
72
  end
55
73
  end
56
74
 
75
+ ########################################################################
76
+
57
77
  def add_error(expected_type:, given_type:)
58
78
  @errors << {
59
79
  expected_type: expected_type,
@@ -92,23 +92,23 @@ module Servactory
92
92
  collection_validator = nil
93
93
  object_schema_validator = nil
94
94
 
95
- return if prepared_types.any? do |type|
96
- if @attribute.collection_mode?
97
- collection_validator = Servactory::Maintenance::Validations::Collection.validate(
98
- value: @value,
99
- types: @attribute.types,
100
- type: type
101
- )
95
+ if @attribute.collection_mode?
96
+ collection_validator = Servactory::Maintenance::Validations::Collection.validate(
97
+ attribute: @attribute,
98
+ types: @types,
99
+ value: @value
100
+ )
102
101
 
103
- collection_validator.valid?
104
- elsif @attribute.hash_mode?
105
- object_schema_validator = Servactory::Maintenance::Validations::ObjectSchema.validate(
106
- object: @value,
107
- schema: @attribute.schema
108
- )
102
+ return if collection_validator.valid?
103
+ elsif @attribute.hash_mode?
104
+ object_schema_validator = Servactory::Maintenance::Validations::ObjectSchema.validate(
105
+ object: @value,
106
+ schema: @attribute.schema
107
+ )
109
108
 
110
- object_schema_validator.valid?
111
- else
109
+ return if object_schema_validator.valid?
110
+ else
111
+ return if prepared_types.any? do |type| # rubocop:disable Style/IfInsideElse
112
112
  @value.is_a?(type)
113
113
  end
114
114
  end
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
6
  MINOR = 0
7
- PATCH = 0
7
+ PATCH = 2
8
8
  PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
data/lib/servactory.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "zeitwerk"
4
4
 
5
- require "active_support/core_ext/string"
5
+ require "active_support/all"
6
6
 
7
7
  loader = Zeitwerk::Loader.for_gem
8
8
  loader.inflector.inflect(
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-05 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: 7.0.8
22
+ version: '7.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '6.0'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: 7.0.8
32
+ version: '7.2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: i18n
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +58,20 @@ dependencies:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
60
  version: '2.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: appraisal
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.5'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.5'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: pry
57
77
  requirement: !ruby/object:Gem::Requirement