u-attributes 1.1.1 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Micro::Attributes
4
- module Features
5
- module StrictInitialize
6
- MISSING_KEYWORD = 'missing keyword'.freeze
7
- MISSING_KEYWORDS = 'missing keywords'.freeze
8
-
9
- protected def attributes=(arg)
10
- arg_hash = AttributesUtils.stringify_hash_keys!(arg)
11
- att_data = self.class.attributes_data({})
12
-
13
- attributes_missing!(ref: att_data, arg: arg_hash)
14
-
15
- att_data.merge(arg_hash).each { |name, value| __attribute_set(name, value) }
16
-
17
- __attributes.freeze
18
- end
19
-
20
- private def attributes_missing!(ref:, arg:)
21
- missing_keys = attributes_missing(ref, arg)
22
-
23
- return if missing_keys.empty?
24
-
25
- label = missing_keys.size == 1 ? MISSING_KEYWORD : MISSING_KEYWORDS
26
-
27
- raise ArgumentError, "#{label}: #{missing_keys.join(', ')}"
28
- end
29
-
30
- private def attributes_missing(ref, arg)
31
- ref.each_with_object([]) do |(key, val), memo|
32
- memo << ":#{key}" if val.nil? && !arg.has_key?(key)
33
- end
34
- end
35
-
36
- private_constant :MISSING_KEYWORD, :MISSING_KEYWORDS
37
- end
38
- end
39
- end