active_model_attributes 0.1.0 → 1.0.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 +21 -0
- data/README.md +5 -5
- data/lib/active_model_attributes/version.rb +1 -1
- data/lib/active_model_attributes.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3801142572b024c4d211d44e922bd3cc629cc5e9
|
4
|
+
data.tar.gz: 87716866f64b6e74c39a3389dbf01afc99542698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc6310f6b495d46392b84c4e6780857d55fc1b66eaadbbdbeb6f6d92768a9e9b16ee396d0b378fb42c1521c888be971cfabd1eeeed3d3545c20e1e49e2f51d13
|
7
|
+
data.tar.gz: c875019c0cb39c14d7fb704f4a156bea8f26ad081612514d64b78a3909f6fc264c6e6d36cd73d0b790371a1812b715e71eebd8216febdc35c3a9fa646a90bcef
|
data/Changelog.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# ActiveModelAttributes Changelog
|
2
|
+
|
3
|
+
## master
|
4
|
+
|
5
|
+
## 1.0.0
|
6
|
+
|
7
|
+
Update notes:
|
8
|
+
|
9
|
+
- 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
|
10
|
+
|
11
|
+
Changes:
|
12
|
+
- [ENHANCEMENT] Use #cast method from types instead of #deserialize by @Azdaroth
|
13
|
+
|
14
|
+
## 0.1.0
|
15
|
+
|
16
|
+
Update notes:
|
17
|
+
|
18
|
+
- None
|
19
|
+
|
20
|
+
Changes:
|
21
|
+
- [FEATURE] Basic implementation by @Azdaroth
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# ActiveModelAttributes [![Build Status](https://travis-ci.org/Azdaroth/active_model_attributes.svg?branch=master)](https://travis-ci.org/Azdaroth/active_model_attributes) [![Coverage Status](https://coveralls.io/repos/github/Azdaroth/active_model_attributes/badge.svg)](https://coveralls.io/github/Azdaroth/active_model_attributes)
|
1
|
+
# ActiveModelAttributes [![Build Status](https://travis-ci.org/Azdaroth/active_model_attributes.svg?branch=master)](https://travis-ci.org/Azdaroth/active_model_attributes) [![Gem Version](https://badge.fury.io/rb/active_model_attributes.svg)](https://rubygems.org/gems/active_model_attributes) [![Coverage Status](https://coveralls.io/repos/github/Azdaroth/active_model_attributes/badge.svg)](https://coveralls.io/github/Azdaroth/active_model_attributes)
|
2
2
|
|
3
|
-
Rails 5.0 comes with a great addition of ActiveRecord Attributes API. However, that's only for ActiveRecord, you can't really use it in
|
3
|
+
Rails 5.0 comes with a great addition of ActiveRecord Attributes API. However, that's only for ActiveRecord, you can't really use it in your ActiveModel models. Fortunately, with this gem it's possible.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -77,11 +77,11 @@ Here's a list of supported types:
|
|
77
77
|
* text
|
78
78
|
* time
|
79
79
|
|
80
|
-
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 `
|
80
|
+
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:
|
81
81
|
|
82
82
|
``` rb
|
83
83
|
class SomeCustomMoneyType < ActiveModel::Type::Integer
|
84
|
-
def
|
84
|
+
def cast(value)
|
85
85
|
return super if value.kind_of?(Numeric)
|
86
86
|
return super if !value.to_s.include?('$')
|
87
87
|
|
@@ -117,7 +117,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
117
117
|
|
118
118
|
## Contributing
|
119
119
|
|
120
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
120
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Azdaroth/active_model_attributes.
|
121
121
|
|
122
122
|
|
123
123
|
## License
|
@@ -32,7 +32,7 @@ module ActiveModelAttributes
|
|
32
32
|
|
33
33
|
def define_attribute_writer(name, cast_type, options)
|
34
34
|
define_method "#{name}=" do |val|
|
35
|
-
deserialized_value = ActiveModel::Type.lookup(cast_type).
|
35
|
+
deserialized_value = ActiveModel::Type.lookup(cast_type).cast(val)
|
36
36
|
instance_variable_set("@#{name}", deserialized_value)
|
37
37
|
end
|
38
38
|
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:
|
4
|
+
version: 1.0.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: 2016-12-
|
11
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- ".gitignore"
|
134
134
|
- ".rspec"
|
135
135
|
- ".travis.yml"
|
136
|
+
- Changelog.md
|
136
137
|
- Gemfile
|
137
138
|
- LICENSE.txt
|
138
139
|
- README.md
|