active_model_attributes 1.3.0 → 1.4.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 +5 -5
- data/Changelog.md +4 -0
- data/README.md +0 -1
- data/lib/active_model_attributes.rb +18 -0
- data/lib/active_model_attributes/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1b52785770a010678b6294e39209216e528883042b84d60ec10326fa94f3555e
|
4
|
+
data.tar.gz: 0c624fed894aee6ba9ed4ff19c0f02caf1eaa515e63c09f045dec2b271ac3559
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5641a65feb0260d15ae4b9e069429b27ff32e74f80c9f96a6f2b072543d4090c873e669ace16cac5e8af629f4e2f2487ae8ed504a539dca46bf26d821d6a59d
|
7
|
+
data.tar.gz: f5eb0699d4d266a4b5615d834899e14b543598eb191d1be07b647586e85a919e6e3b89c39d82c954e9a752eb4847136600bab3d39eacf0a2fbe614eeb8b47b18
|
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -74,7 +74,6 @@ Here's a list of supported types:
|
|
74
74
|
* immutable_string
|
75
75
|
* integer
|
76
76
|
* string
|
77
|
-
* text
|
78
77
|
* time
|
79
78
|
|
80
79
|
You can also add your custom types. Just create a class inheriting from `ActiveModel::Type::Value` or already existing type, e.g. `ActiveModel::Type::Integer`, define `cast` method and register the new type:
|
@@ -5,6 +5,8 @@ require "active_model/type"
|
|
5
5
|
module ActiveModelAttributes
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
delegate :type_for_attribute, :has_attribute?, to: :class
|
9
|
+
|
8
10
|
included do
|
9
11
|
class_attribute :attributes_registry, instance_accessor: false
|
10
12
|
self.attributes_registry = {}
|
@@ -46,5 +48,21 @@ module ActiveModelAttributes
|
|
46
48
|
end
|
47
49
|
include wrapper
|
48
50
|
end
|
51
|
+
|
52
|
+
def type_for_attribute(attr)
|
53
|
+
type_desc = attributes_registry[attr.to_sym]
|
54
|
+
return ActiveModel::Type::Value.new if type_desc.nil?
|
55
|
+
|
56
|
+
if type_desc[0].is_a?(Symbol)
|
57
|
+
type, options = type_desc
|
58
|
+
ActiveModel::Type.lookup(type, **options.except(*SERVICE_ATTRIBUTES))
|
59
|
+
else
|
60
|
+
type_desc[0]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def has_attribute?(attr)
|
65
|
+
attributes_registry.key?(attr.to_sym)
|
66
|
+
end
|
49
67
|
end
|
50
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Galanciak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.7.6
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: ActiveModel extension with support for ActiveRecord-like Attributes API
|