active_model_attributes 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +6 -3
- data/active_model_attributes.gemspec +2 -2
- data/lib/active_model_attributes.rb +14 -8
- data/lib/active_model_attributes/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe3f5ecf3b64abb8d80111281f84fd1aaf90371e
|
4
|
+
data.tar.gz: 4e36ed14080754929e8e2ef78435ca1ca5f70b41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54c2b121da6acf30b30148752bb91f049d6db71c9fe2a666711cfb002e89c9af669cee0a485ea4e2e218c4a8d3f75ced7936fc16550786ecc50918e9b67ba550
|
7
|
+
data.tar.gz: 7e0ae5cc5559037b672de366470f2c69350aacef5f61386a356330bc410e829447269d396aab7c19b5ca931b3e38898d6da8800d196123a00122bc46e523e6ab
|
data/Changelog.md
CHANGED
@@ -2,15 +2,19 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.2.0
|
6
|
+
|
7
|
+
Changes:
|
8
|
+
- [ENHANCEMENT] Wrap definition of attributes' readers and writers inside anonymous modules to be able to call `super` by @Azdaroth
|
9
|
+
|
5
10
|
## 1.1.0
|
6
11
|
|
7
12
|
Changes:
|
8
|
-
- [BUGFIX] Pass `options` argument to `ActiveModel::Type.lookup` in attribute writers @jughead
|
13
|
+
- [BUGFIX] Pass `options` argument to `ActiveModel::Type.lookup` in attribute writers by @jughead
|
9
14
|
|
10
15
|
## 1.0.0
|
11
16
|
|
12
17
|
Update notes:
|
13
|
-
|
14
18
|
- Breaking change: the attribute's setter now calls #cast method on type instead of #deserialize. If you have defined any custom type, just rename the method from #deserialize to #cast
|
15
19
|
|
16
20
|
Changes:
|
@@ -19,7 +23,6 @@ Changes:
|
|
19
23
|
## 0.1.0
|
20
24
|
|
21
25
|
Update notes:
|
22
|
-
|
23
26
|
- None
|
24
27
|
|
25
28
|
Changes:
|
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.
|
25
|
-
spec.add_development_dependency "rake", "~>
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_development_dependency "pry"
|
28
28
|
spec.add_development_dependency "pry-byebug"
|
@@ -23,19 +23,25 @@ module ActiveModelAttributes
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def define_attribute_reader(name, options)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
wrapper = Module.new do
|
27
|
+
provided_default = options.fetch(:default) { NO_DEFAULT_PROVIDED }
|
28
|
+
define_method name do
|
29
|
+
return instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}")
|
30
|
+
return if provided_default == NO_DEFAULT_PROVIDED
|
31
|
+
provided_default.respond_to?(:call) && provided_default.call || provided_default
|
32
|
+
end
|
31
33
|
end
|
34
|
+
include wrapper
|
32
35
|
end
|
33
36
|
|
34
37
|
def define_attribute_writer(name, cast_type, options)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
wrapper = Module.new do
|
39
|
+
define_method "#{name}=" do |val|
|
40
|
+
deserialized_value = ActiveModel::Type.lookup(cast_type, **options.except(*SERVICE_ATTRIBUTES)).cast(val)
|
41
|
+
instance_variable_set("@#{name}", deserialized_value)
|
42
|
+
end
|
38
43
|
end
|
44
|
+
include wrapper
|
39
45
|
end
|
40
46
|
end
|
41
47
|
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.2.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-04
|
11
|
+
date: 2017-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.14'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.14'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|