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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 18997005eb624d93e538c3fa8b31188d89065963
4
- data.tar.gz: 7c7d99560c707494a5003f55f1cd06f763afb0b7
2
+ SHA256:
3
+ metadata.gz: 1b52785770a010678b6294e39209216e528883042b84d60ec10326fa94f3555e
4
+ data.tar.gz: 0c624fed894aee6ba9ed4ff19c0f02caf1eaa515e63c09f045dec2b271ac3559
5
5
  SHA512:
6
- metadata.gz: 05a36349633d95a359ae44d90afc38b7aa6e20d8fa2bdf6f8f5cb9d2010cc26b7b30a6aaa7a63d6547e3907890ee01d874e02a91a7851898a1483b7e84f0d95d
7
- data.tar.gz: bea729fb6f61d79e09c865fc81fde8c6b1aadd0eddc7d0232e8a653ed42b6442304b5693a5815b784f9cbdbb45513a38f89849b5a582032d2fcb4f72c8213914
6
+ metadata.gz: a5641a65feb0260d15ae4b9e069429b27ff32e74f80c9f96a6f2b072543d4090c873e669ace16cac5e8af629f4e2f2487ae8ed504a539dca46bf26d821d6a59d
7
+ data.tar.gz: f5eb0699d4d266a4b5615d834899e14b543598eb191d1be07b647586e85a919e6e3b89c39d82c954e9a752eb4847136600bab3d39eacf0a2fbe614eeb8b47b18
data/Changelog.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.4.0
6
+
7
+ - [FEATURE] Add methods for introspection of types and attributes by @fsateler
8
+
5
9
  ## 1.3.0
6
10
 
7
11
  - [FEATURE] Allow untyped attributes by defaulting to the `ActiveModel::Type::Value` type by @alan
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
@@ -1,3 +1,3 @@
1
1
  module ActiveModelAttributes
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  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.3.0
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-03-03 00:00:00.000000000 Z
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.5.1
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