active_model_attributes 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe3f5ecf3b64abb8d80111281f84fd1aaf90371e
4
- data.tar.gz: 4e36ed14080754929e8e2ef78435ca1ca5f70b41
3
+ metadata.gz: 18997005eb624d93e538c3fa8b31188d89065963
4
+ data.tar.gz: 7c7d99560c707494a5003f55f1cd06f763afb0b7
5
5
  SHA512:
6
- metadata.gz: 54c2b121da6acf30b30148752bb91f049d6db71c9fe2a666711cfb002e89c9af669cee0a485ea4e2e218c4a8d3f75ced7936fc16550786ecc50918e9b67ba550
7
- data.tar.gz: 7e0ae5cc5559037b672de366470f2c69350aacef5f61386a356330bc410e829447269d396aab7c19b5ca931b3e38898d6da8800d196123a00122bc46e523e6ab
6
+ metadata.gz: 05a36349633d95a359ae44d90afc38b7aa6e20d8fa2bdf6f8f5cb9d2010cc26b7b30a6aaa7a63d6547e3907890ee01d874e02a91a7851898a1483b7e84f0d95d
7
+ data.tar.gz: bea729fb6f61d79e09c865fc81fde8c6b1aadd0eddc7d0232e8a653ed42b6442304b5693a5815b784f9cbdbb45513a38f89849b5a582032d2fcb4f72c8213914
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.3.0
6
+
7
+ - [FEATURE] Allow untyped attributes by defaulting to the `ActiveModel::Type::Value` type by @alan
8
+
5
9
  ## 1.2.0
6
10
 
7
11
  Changes:
@@ -15,7 +15,7 @@ module ActiveModelAttributes
15
15
  SERVICE_ATTRIBUTES = %i(default user_provided_default).freeze
16
16
  private_constant :NO_DEFAULT_PROVIDED
17
17
 
18
- def attribute(name, cast_type, **options)
18
+ def attribute(name, cast_type = ActiveModel::Type::Value.new, **options)
19
19
  self.attributes_registry = attributes_registry.merge(name => [cast_type, options])
20
20
 
21
21
  define_attribute_reader(name, options)
@@ -37,7 +37,10 @@ module ActiveModelAttributes
37
37
  def define_attribute_writer(name, cast_type, options)
38
38
  wrapper = Module.new do
39
39
  define_method "#{name}=" do |val|
40
- deserialized_value = ActiveModel::Type.lookup(cast_type, **options.except(*SERVICE_ATTRIBUTES)).cast(val)
40
+ if cast_type.is_a?(Symbol)
41
+ cast_type = ActiveModel::Type.lookup(cast_type, **options.except(*SERVICE_ATTRIBUTES))
42
+ end
43
+ deserialized_value = cast_type.cast(val)
41
44
  instance_variable_set("@#{name}", deserialized_value)
42
45
  end
43
46
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveModelAttributes
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.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.2.0
4
+ version: 1.3.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: 2017-06-04 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler