deco_lite 0.2.4 → 0.2.5
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/CHANGELOG.md +13 -5
- data/Gemfile.lock +1 -1
- data/lib/deco_lite/field_conflictable.rb +16 -10
- data/lib/deco_lite/field_creatable.rb +2 -0
- data/lib/deco_lite/field_name_namespaceable.rb +17 -0
- data/lib/deco_lite/field_validatable.rb +4 -4
- data/lib/deco_lite/model.rb +3 -5
- data/lib/deco_lite/options_validatable.rb +2 -2
- data/lib/deco_lite/version.rb +1 -1
- data/lib/deco_lite.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74286df21784817e45f4d615081bfeac44d90f13d8200bc8f066107e8d0f773f
|
4
|
+
data.tar.gz: 57dcc52147494eb3caf59159cbb21bc23bb6788d0b6315ebc1ddd8cf1868c779
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b79af6a65df899227821e4a02bf17587f1f423042a4280a54525c8469c1c3344f3dd2c3b16bd0de477c711d27ed04527295ca37e811c1c829037379509971ac6
|
7
|
+
data.tar.gz: 7d1b5dea80d0af672713d18675166207e2d62ab51aff84045411d02344529a32de513df76d394e3769dfb14a69d0742f18e850398dc9b4cc6bac10eb5c72ecec
|
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,32 @@
|
|
1
|
+
### 0.2.5
|
2
|
+
* Changes
|
3
|
+
* Remove init of `@field_names = []` in `Model#initialize` as unnecessary - FieldNamesPersistable takes care of this.
|
4
|
+
* Bug fixes
|
5
|
+
* Fix but that does not take into account option :namespace when determining whether or not a field name conflicts with an existing attribute (already exists).
|
6
|
+
|
1
7
|
### 0.2.4
|
2
8
|
* Changes
|
3
9
|
* Change DecoLite::Model#load to #load! as it alters the object, give deprecation warning when calling #load.
|
4
10
|
* FieldConflictable now expliticly prohibits loading fields that conflict with attributes that are native to the receiver. In other words, you cannot load fields with names like :to_s, :tap, :hash, etc.
|
5
11
|
* FieldCreatable now creates attr_accessors on the instance using #define_singleton_method, not at the class level (i.e. self.class.attr_accessor) (see bug fixes).
|
6
|
-
*
|
12
|
+
* Bug fixes
|
7
13
|
* Fix bug that used self.class.attr_accessor in DecoLite::FieldCreatable to create attributes, which forced every object of that class subsequently created have the accessors created which caused field name conflicts across DecoLite::Model objects.
|
8
14
|
|
9
15
|
### 0.2.3
|
10
|
-
*
|
16
|
+
* Bug fixes
|
17
|
+
* Fix bug that added duplcate field names to Model#field_names.
|
11
18
|
|
12
19
|
### 0.2.2
|
13
|
-
*
|
20
|
+
* Bug fixes
|
21
|
+
* Fix bug requiring support codez in lib/deco_lite.rb.
|
14
22
|
|
15
23
|
### 0.2.1
|
16
|
-
*
|
24
|
+
* Changes
|
17
25
|
* Add mad_flatter gem runtime dependency.
|
18
26
|
* Refactor to let mad_flatter handle the Hash flattening.
|
19
27
|
|
20
28
|
### 0.1.1
|
21
|
-
*
|
29
|
+
* Changes
|
22
30
|
* Update gems and especially rake gem version to squash CVE-2020-8130, see https://github.com/advisories/GHSA-jppv-gw3r-w3q8.
|
23
31
|
* Fix rubocop violations.
|
24
32
|
|
data/Gemfile.lock
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'field_name_namespaceable'
|
3
4
|
require_relative 'fields_optionable'
|
4
5
|
|
5
6
|
module DecoLite
|
6
7
|
# Defines methods to to manage fields that conflict with
|
7
8
|
# existing model attributes.
|
8
9
|
module FieldConflictable
|
10
|
+
include FieldNameNamespaceable
|
9
11
|
include FieldsOptionable
|
10
12
|
|
11
13
|
def validate_field_conflicts!(field_name:, options:)
|
12
14
|
return unless field_conflict?(field_name: field_name, options: options)
|
13
15
|
|
16
|
+
field_name = field_name_or_field_name_with_namespace field_name: field_name, options: options
|
17
|
+
|
14
18
|
raise "Field :#{field_name} conflicts with existing method(s) " \
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
":#{field_name} and/or :#{field_name}=; " \
|
20
|
+
'this will raise an error when loading using strict mode ' \
|
21
|
+
"(i.e. options: { #{OPTION_FIELDS}: :#{OPTION_FIELDS_STRICT} }) " \
|
22
|
+
'or if the method(s) are native to the object (e.g :to_s, :==, etc.).'
|
19
23
|
end
|
20
24
|
|
21
25
|
# This method returns true
|
22
26
|
def field_conflict?(field_name:, options:)
|
23
27
|
# If field_name was already added using Model#load, there is only a
|
24
28
|
# conflict if options.strict? is true.
|
25
|
-
if field_names_include?(field_name: field_name)
|
26
|
-
return options.strict?
|
27
|
-
end
|
29
|
+
return options.strict? if field_names_include?(field_name: field_name, options: options)
|
28
30
|
|
29
31
|
# If we get here, we know that :field_name does not exist as an
|
30
32
|
# attribute on the model. If the attribute already exists on the
|
31
33
|
# model, this is a conflict because we cannot override an attribute
|
32
34
|
# that already exists on the model
|
33
|
-
attr_accessor_exist?(field_name: field_name)
|
35
|
+
attr_accessor_exist?(field_name: field_name, options: options)
|
34
36
|
end
|
35
37
|
|
36
|
-
def field_names_include?(field_name:)
|
38
|
+
def field_names_include?(field_name:, options:)
|
39
|
+
field_name = field_name_or_field_name_with_namespace field_name: field_name, options: options
|
40
|
+
|
37
41
|
field_names.include? field_name
|
38
42
|
end
|
39
43
|
|
40
|
-
def attr_accessor_exist?(field_name:)
|
44
|
+
def attr_accessor_exist?(field_name:, options:)
|
45
|
+
field_name = field_name_or_field_name_with_namespace field_name: field_name, options: options
|
46
|
+
|
41
47
|
respond_to?(field_name) || respond_to?(:"#{field_name}=")
|
42
48
|
end
|
43
49
|
end
|
@@ -30,6 +30,7 @@ module DecoLite
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
33
34
|
def create_field_getter(field_name:, options:)
|
34
35
|
define_singleton_method(field_name) do
|
35
36
|
instance_variable_get "@#{field_name}"
|
@@ -41,5 +42,6 @@ module DecoLite
|
|
41
42
|
instance_variable_set "@#{field_name}", value
|
42
43
|
end
|
43
44
|
end
|
45
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
44
46
|
end
|
45
47
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DecoLite
|
4
|
+
# Defines methods to transform a field name into a field name
|
5
|
+
# with a namespace.
|
6
|
+
module FieldNameNamespaceable
|
7
|
+
def field_name_or_field_name_with_namespace(field_name:, options:)
|
8
|
+
return field_name unless options.namespace?
|
9
|
+
|
10
|
+
field_name_with_namespace(field_name: field_name, namespace: options.namespace)
|
11
|
+
end
|
12
|
+
|
13
|
+
def field_name_with_namespace(field_name:, namespace:)
|
14
|
+
"#{namespace}_#{field_name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module DecoLite
|
4
4
|
# Defines methods validate field (attribute) names.
|
5
5
|
module FieldValidatable
|
6
|
-
FIELD_NAME_REGEX =
|
6
|
+
FIELD_NAME_REGEX = %r{\A(?:[a-z_]\w*[?!=]?|\[\]=?|<<|>>|\*\*|[!~+*/%&^|-]|[<>]=?|<=>|={2,3}|![=~]|=~)\z}i
|
7
7
|
|
8
8
|
module_function
|
9
9
|
|
10
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
10
11
|
def validate_field_name!(field_name:, options: nil)
|
11
|
-
|
12
|
-
raise "field_name '#{field_name}' is not a valid field name."
|
13
|
-
end
|
12
|
+
raise "field_name '#{field_name}' is not a valid field name." unless FIELD_NAME_REGEX.match?(field_name)
|
14
13
|
end
|
14
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
15
15
|
end
|
16
16
|
end
|
data/lib/deco_lite/model.rb
CHANGED
@@ -25,8 +25,6 @@ module DecoLite
|
|
25
25
|
validate :validate_required_fields
|
26
26
|
|
27
27
|
def initialize(options: {})
|
28
|
-
@field_names = []
|
29
|
-
|
30
28
|
# Accept whatever options are sent, but make sure
|
31
29
|
# we have defaults set up. #options_with_defaults
|
32
30
|
# will merge options into OptionsDefaultable::DEFAULT_OPTIONS
|
@@ -49,10 +47,10 @@ module DecoLite
|
|
49
47
|
end
|
50
48
|
|
51
49
|
def load(hash:, options: {})
|
52
|
-
puts 'WARNING: DecoLite::Model#load will be deprecated in a future release;' \
|
53
|
-
|
50
|
+
puts 'WARNING: DecoLite::Model#load will be deprecated in a future release; ' \
|
51
|
+
'use DecoLite::Model#load! instead!'
|
54
52
|
|
55
|
-
|
53
|
+
load!(hash: hash, options: options)
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
@@ -35,7 +35,7 @@ module DecoLite
|
|
35
35
|
|
36
36
|
raise ArgumentError,
|
37
37
|
"option :fields value or type is invalid. #{OPTION_FIELDS_VALUES} (Symbol) " \
|
38
|
-
|
38
|
+
"was expected, but '#{fields}' (#{fields.class}) was received."
|
39
39
|
end
|
40
40
|
|
41
41
|
def validate_option_namespace!(namespace:)
|
@@ -43,7 +43,7 @@ module DecoLite
|
|
43
43
|
return if namespace.blank? || namespace.is_a?(Symbol)
|
44
44
|
|
45
45
|
raise ArgumentError, 'option :namespace value or type is invalid. A Symbol was expected, ' \
|
46
|
-
|
46
|
+
"but '#{namespace}' (#{namespace.class}) was received."
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/lib/deco_lite/version.rb
CHANGED
data/lib/deco_lite.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'deco_lite/field_assignable'
|
4
4
|
require_relative 'deco_lite/field_conflictable'
|
5
5
|
require_relative 'deco_lite/field_creatable'
|
6
|
+
require_relative 'deco_lite/field_name_namespaceable'
|
6
7
|
require_relative 'deco_lite/field_names_persistable'
|
7
8
|
require_relative 'deco_lite/field_requireable'
|
8
9
|
require_relative 'deco_lite/field_retrievable'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deco_lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene M. Angelo, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -261,6 +261,7 @@ files:
|
|
261
261
|
- lib/deco_lite/field_assignable.rb
|
262
262
|
- lib/deco_lite/field_conflictable.rb
|
263
263
|
- lib/deco_lite/field_creatable.rb
|
264
|
+
- lib/deco_lite/field_name_namespaceable.rb
|
264
265
|
- lib/deco_lite/field_names_persistable.rb
|
265
266
|
- lib/deco_lite/field_requireable.rb
|
266
267
|
- lib/deco_lite/field_retrievable.rb
|