u-attributes 1.1.1 → 2.1.1
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.sh +9 -2
- data/.travis.yml +5 -5
- data/Gemfile +11 -2
- data/LICENSE.txt +2 -2
- data/README.md +427 -282
- data/Rakefile +5 -5
- data/assets/u-attributes_logo_v1.png +0 -0
- data/bin/console +4 -4
- data/lib/micro/attributes.rb +95 -42
- data/lib/micro/attributes/diff.rb +52 -0
- data/lib/micro/attributes/features.rb +41 -33
- data/lib/micro/attributes/features/activemodel_validations.rb +17 -23
- data/lib/micro/attributes/features/diff.rb +2 -50
- data/lib/micro/attributes/features/initialize.rb +5 -0
- data/lib/micro/attributes/features/initialize/strict.rb +19 -0
- data/lib/micro/attributes/macros.rb +53 -23
- data/lib/micro/attributes/utils.rb +25 -0
- data/lib/micro/attributes/version.rb +1 -1
- data/lib/micro/attributes/with.rb +6 -6
- data/u-attributes.gemspec +19 -12
- metadata +48 -11
- data/Gemfile.lock +0 -29
- data/lib/micro/attributes/attributes_utils.rb +0 -21
- data/lib/micro/attributes/features/strict_initialize.rb +0 -39
@@ -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
|