active_attr 0.13.1 → 0.14.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.
Potentially problematic release.
This version of active_attr might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +0 -17
- data/CHANGELOG.md +14 -0
- data/Gemfile +4 -5
- data/README.md +140 -112
- data/active_attr.gemspec +8 -1
- data/gemfiles/rails_3_0.gemfile +0 -4
- data/gemfiles/rails_3_1.gemfile +0 -4
- data/gemfiles/rails_3_2.gemfile +0 -4
- data/gemfiles/rails_4_0.gemfile +1 -1
- data/gemfiles/rails_4_1.gemfile +1 -1
- data/gemfiles/rails_4_2.gemfile +1 -1
- data/gemfiles/rails_5_0.gemfile +1 -1
- data/gemfiles/rails_5_1.gemfile +1 -1
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/gemfiles/rails_head.gemfile +1 -1
- data/lib/active_attr.rb +1 -1
- data/lib/active_attr/attributes.rb +62 -9
- data/lib/active_attr/chainable_initialization.rb +2 -6
- data/lib/active_attr/logger.rb +1 -1
- data/lib/active_attr/mass_assignment.rb +2 -2
- data/lib/active_attr/matchers/have_attribute_matcher.rb +1 -1
- data/lib/active_attr/model.rb +1 -0
- data/lib/active_attr/query_attributes.rb +1 -1
- data/lib/active_attr/railtie.rb +5 -0
- data/lib/active_attr/typecasting/boolean_typecaster.rb +8 -0
- data/lib/active_attr/version.rb +1 -1
- data/spec/functional/active_attr/attributes_spec.rb +8 -8
- data/spec/functional/active_attr/matchers/have_attribute_matcher_spec.rb +48 -0
- data/spec/functional/active_attr/model_spec.rb +47 -0
- data/spec/unit/active_attr/attribute_defaults_spec.rb +8 -0
- data/spec/unit/active_attr/attributes_spec.rb +91 -0
- data/spec/unit/active_attr/typecasting/big_decimal_typecaster_spec.rb +4 -0
- data/spec/unit/active_attr/typecasting/boolean_typecaster_spec.rb +3 -3
- metadata +27 -13
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27d7a6a18d57befed3918f2bfff542bd99d9ef58fa7cfe68b028b6165cc2e001
|
4
|
+
data.tar.gz: 050735d5e29e679f140f9521452dd75266116efd94c9b72a6215f4bb52834aff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0648dc4bb4168744604929bdc7f32d3e5ba2a5ffea45e3e7c4c27f6cfa3ce2f7aafe220b09f0cb239363bf4197ae7bfde959c52173fed65d5fbfd2f4cdd7efcc'
|
7
|
+
data.tar.gz: 92d9884debc077a14e90627eeef4fed79fb927467d1934cc7739198541f27b9da380cfcf2de3518c5c111113a6fbc9dbd1a83b3af413d421252a2829da5f4de5
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
rvm:
|
4
|
-
- ree
|
5
4
|
- 1.9.2
|
6
5
|
- 1.9.3
|
7
6
|
- 2.0.0
|
@@ -35,20 +34,12 @@ matrix:
|
|
35
34
|
gemfile: gemfiles/rails_3_0.gemfile
|
36
35
|
- rvm: 2.6.3
|
37
36
|
gemfile: gemfiles/rails_3_0.gemfile
|
38
|
-
- rvm: ree
|
39
|
-
gemfile: gemfiles/rails_4_0.gemfile
|
40
37
|
- rvm: 1.9.2
|
41
38
|
gemfile: gemfiles/rails_4_0.gemfile
|
42
|
-
- rvm: ree
|
43
|
-
gemfile: gemfiles/rails_4_1.gemfile
|
44
39
|
- rvm: 1.9.2
|
45
40
|
gemfile: gemfiles/rails_4_1.gemfile
|
46
|
-
- rvm: ree
|
47
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
48
41
|
- rvm: 1.9.2
|
49
42
|
gemfile: gemfiles/rails_4_2.gemfile
|
50
|
-
- rvm: ree
|
51
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
52
43
|
- rvm: 1.9.2
|
53
44
|
gemfile: gemfiles/rails_5_0.gemfile
|
54
45
|
- rvm: 1.9.3
|
@@ -57,8 +48,6 @@ matrix:
|
|
57
48
|
gemfile: gemfiles/rails_5_0.gemfile
|
58
49
|
- rvm: 2.1.10
|
59
50
|
gemfile: gemfiles/rails_5_0.gemfile
|
60
|
-
- rvm: ree
|
61
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
62
51
|
- rvm: 1.9.2
|
63
52
|
gemfile: gemfiles/rails_5_1.gemfile
|
64
53
|
- rvm: 1.9.3
|
@@ -67,8 +56,6 @@ matrix:
|
|
67
56
|
gemfile: gemfiles/rails_5_1.gemfile
|
68
57
|
- rvm: 2.1.10
|
69
58
|
gemfile: gemfiles/rails_5_1.gemfile
|
70
|
-
- rvm: ree
|
71
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
72
59
|
- rvm: 1.9.2
|
73
60
|
gemfile: gemfiles/rails_5_2.gemfile
|
74
61
|
- rvm: 1.9.3
|
@@ -77,8 +64,6 @@ matrix:
|
|
77
64
|
gemfile: gemfiles/rails_5_2.gemfile
|
78
65
|
- rvm: 2.1.10
|
79
66
|
gemfile: gemfiles/rails_5_2.gemfile
|
80
|
-
- rvm: ree
|
81
|
-
gemfile: Gemfile
|
82
67
|
- rvm: 1.9.2
|
83
68
|
gemfile: Gemfile
|
84
69
|
- rvm: 1.9.3
|
@@ -93,8 +78,6 @@ matrix:
|
|
93
78
|
gemfile: Gemfile
|
94
79
|
- rvm: 2.4.6
|
95
80
|
gemfile: Gemfile
|
96
|
-
- rvm: ree
|
97
|
-
gemfile: gemfiles/rails_head.gemfile
|
98
81
|
- rvm: 1.9.2
|
99
82
|
gemfile: gemfiles/rails_head.gemfile
|
100
83
|
- rvm: 1.9.3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# ActiveAttr 0.14.0 (June 10, 2019) #
|
2
|
+
|
3
|
+
* Drop support for Ruby versions below 1.9.2
|
4
|
+
* #139 Changed Typecasting::BooleanTypecaster to cast nil and empty
|
5
|
+
strings to false (Corin Langosch)
|
6
|
+
* Attributes#inspect is now filtered based on filtered_attributes,
|
7
|
+
which defaults to `Rails.application.config.filter_parameters` in
|
8
|
+
Rails apps.
|
9
|
+
* #143 Changed Attributes to allocate less objects (Chris Grigg)
|
10
|
+
* #153 Changed HaveAttributeMatcher#with_default_value_of to support
|
11
|
+
Procs (Yoshiyuki Hirano)
|
12
|
+
* #145 Add ActiveModel::Validations::Callbacks to ActiveAttr::Model
|
13
|
+
(Kazuki BABA)
|
14
|
+
|
1
15
|
# ActiveAttr 0.13.1 (April 25, 2019) #
|
2
16
|
|
3
17
|
* ActiveAttr now supports Rails 6.0
|
data/Gemfile
CHANGED
@@ -4,13 +4,13 @@ gemspec :development_group => :test
|
|
4
4
|
|
5
5
|
gem "activemodel", ">= 5.2.0.beta1", "< 6.1"
|
6
6
|
gem "activesupport", ">= 5.2.0.beta1", "< 6.1"
|
7
|
-
gem "actionpack", ">= 5.2.0.beta1", "< 6.1"
|
7
|
+
gem "actionpack", ">= 5.2.0.beta1", "< 6.1"
|
8
8
|
gem "activemodel-serializers-xml", :group => :test
|
9
9
|
gem "protected_attributes_continued", :group => :test
|
10
10
|
|
11
11
|
group :development do
|
12
|
-
gem "debugger"
|
13
|
-
gem "byebug"
|
12
|
+
gem "debugger" if RUBY_VERSION < "2.0"
|
13
|
+
gem "byebug" unless RUBY_VERSION < "2.0"
|
14
14
|
gem "growl"
|
15
15
|
gem "guard"
|
16
16
|
gem "guard-bundler"
|
@@ -18,8 +18,7 @@ group :development do
|
|
18
18
|
gem "rb-fsevent"
|
19
19
|
gem "rdiscount"
|
20
20
|
gem "rdoc"
|
21
|
-
gem "
|
22
|
-
gem "spec_coverage", :platforms => [:mri_19, :mri_20, :mri_21, :mri_22, :mri_23, :mri_24], :git => "https://github.com/getaroom/spec_coverage.git"
|
21
|
+
gem "spec_coverage", :git => "https://github.com/getaroom/spec_coverage.git"
|
23
22
|
gem "travis"
|
24
23
|
gem "yard"
|
25
24
|
end
|
data/README.md
CHANGED
@@ -9,7 +9,6 @@ reinventing the wheel. Think of ActiveAttr as the stuff ActiveModel left out.
|
|
9
9
|
|
10
10
|
ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
|
11
11
|
|
12
|
-
[![Models Models Every Where][speakerdeck slide]][speakerdeck]
|
13
12
|
[![ActiveAttr Railscast][railscast poster]][railscast]
|
14
13
|
|
15
14
|
* [Slides][speakerdeck]
|
@@ -26,7 +25,6 @@ ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
|
|
26
25
|
[rubygems]: http://rubygems.org/gems/active_attr
|
27
26
|
[protected_attributes]: https://github.com/westonganger/protected_attributes_continued
|
28
27
|
[strong_parameters]: https://github.com/rails/strong_parameters
|
29
|
-
[speakerdeck slide]: https://speakerd.s3.amazonaws.com/presentations/4f31f1dec583b4001f008ec3/thumb_slide_0.jpg
|
30
28
|
[speakerdeck]: https://speakerdeck.com/u/cgriego/p/models-models-every-where
|
31
29
|
[travis badge]: https://secure.travis-ci.org/cgriego/active_attr.svg?branch=master
|
32
30
|
[travis]: http://travis-ci.org/cgriego/active_attr
|
@@ -38,96 +36,108 @@ ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
|
|
38
36
|
Including the Attributes module into your class gives you a DSL for defining
|
39
37
|
the attributes of your model.
|
40
38
|
|
41
|
-
|
42
|
-
|
39
|
+
```ruby
|
40
|
+
class Person
|
41
|
+
include ActiveAttr::Attributes
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
attribute :first_name
|
44
|
+
attribute :last_name
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
person = Person.new
|
48
|
+
person.first_name = "Chris"
|
49
|
+
person.last_name = "Griego"
|
50
|
+
person.attributes #=> {"first_name"=>"Chris", "last_name"=>"Griego"}
|
51
|
+
```
|
52
52
|
|
53
53
|
#### AttributeDefaults ####
|
54
54
|
|
55
55
|
Including the AttributeDefaults module into your class builds on Attributes by
|
56
56
|
allowing defaults to be declared with attributes.
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
```ruby
|
59
|
+
class Person
|
60
|
+
include ActiveAttr::AttributeDefaults
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
attribute :first_name, :default => "John"
|
63
|
+
attribute :last_name, :default => "Doe"
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
person = Person.new
|
67
|
+
person.first_name #=> "John"
|
68
|
+
person.last_name #=> "Doe"
|
69
|
+
```
|
68
70
|
|
69
71
|
#### QueryAttributes ####
|
70
72
|
|
71
73
|
Including the QueryAttributes module into your class builds on Attributes by
|
72
74
|
providing instance methods for querying your attributes.
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
+
```ruby
|
77
|
+
class Person
|
78
|
+
include ActiveAttr::QueryAttributes
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
attribute :first_name
|
81
|
+
attribute :last_name
|
82
|
+
end
|
80
83
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
person = Person.new
|
85
|
+
person.first_name = "Chris"
|
86
|
+
person.first_name? #=> true
|
87
|
+
person.last_name? #=> false
|
88
|
+
```
|
85
89
|
|
86
90
|
#### TypecastedAttributes ####
|
87
91
|
|
88
92
|
Including the TypecastedAttributes module into your class builds on Attributes
|
89
93
|
by providing type conversion for your attributes.
|
90
94
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
+
```ruby
|
96
|
+
class Person
|
97
|
+
include ActiveAttr::TypecastedAttributes
|
98
|
+
attribute :age, :type => Integer
|
99
|
+
end
|
95
100
|
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
person = Person.new
|
102
|
+
person.age = "29"
|
103
|
+
person.age #=> 29
|
104
|
+
```
|
99
105
|
|
100
106
|
### BasicModel ###
|
101
107
|
|
102
108
|
Including the BasicModel module into your class gives you the bare minimum
|
103
109
|
required for your model to meet the ActiveModel API requirements.
|
104
110
|
|
105
|
-
|
106
|
-
|
107
|
-
|
111
|
+
```ruby
|
112
|
+
class Person
|
113
|
+
include ActiveAttr::BasicModel
|
114
|
+
end
|
108
115
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
116
|
+
Person.model_name.plural #=> "people"
|
117
|
+
person = Person.new
|
118
|
+
person.valid? #=> true
|
119
|
+
person.errors.full_messages #=> []
|
120
|
+
```
|
113
121
|
|
114
122
|
### BlockInitialization ###
|
115
123
|
|
116
124
|
Including the BlockInitialization module into your class will yield the model
|
117
125
|
instance to a block passed to when creating a new instance.
|
118
126
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
127
|
+
```ruby
|
128
|
+
class Person
|
129
|
+
include ActiveAttr::BlockInitialization
|
130
|
+
attr_accessor :first_name, :last_name
|
131
|
+
end
|
123
132
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
133
|
+
person = Person.new do |p|
|
134
|
+
p.first_name = "Chris"
|
135
|
+
p.last_name = "Griego"
|
136
|
+
end
|
128
137
|
|
129
|
-
|
130
|
-
|
138
|
+
person.first_name #=> "Chris"
|
139
|
+
person.last_name #=> "Griego"
|
140
|
+
```
|
131
141
|
|
132
142
|
### Logger ###
|
133
143
|
|
@@ -137,18 +147,20 @@ be configured on an instance, subclass, class, parent class, and globally by
|
|
137
147
|
setting ActiveAttr::Logger.logger. When using Rails, the Rails framework
|
138
148
|
logger will be configured by default.
|
139
149
|
|
140
|
-
|
141
|
-
|
142
|
-
|
150
|
+
```ruby
|
151
|
+
class Person
|
152
|
+
include ActiveAttr::Logger
|
153
|
+
end
|
143
154
|
|
144
|
-
|
145
|
-
|
146
|
-
|
155
|
+
Person.logger = Logger.new(STDOUT)
|
156
|
+
Person.logger? #=> true
|
157
|
+
Person.logger.info "Logging an informational message"
|
147
158
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
159
|
+
person = Person.new
|
160
|
+
person.logger? #=> true
|
161
|
+
person.logger = Logger.new(STDERR)
|
162
|
+
person.logger.warn "Logging a warning message"
|
163
|
+
```
|
152
164
|
|
153
165
|
### MassAssignment ###
|
154
166
|
|
@@ -156,66 +168,76 @@ Including the MassAssignment module into your class gives you methods for bulk
|
|
156
168
|
initializing and updating the attributes of your model. Any unknown attributes
|
157
169
|
are silently ignored.
|
158
170
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
171
|
+
```ruby
|
172
|
+
class Person
|
173
|
+
include ActiveAttr::MassAssignment
|
174
|
+
attr_accessor :first_name, :last_name, :age
|
175
|
+
end
|
163
176
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
177
|
+
person = Person.new(:first_name => "Christopher", :last_name => "Griego")
|
178
|
+
person.attributes = { :first_name => "Chris", :age => 21 }
|
179
|
+
person.first_name #=> "Chris"
|
180
|
+
person.last_name #=> "Griego"
|
181
|
+
```
|
168
182
|
|
169
183
|
MassAssignment supports mass assignment security/sanitization if a sanitizer
|
170
184
|
is included in the model. If using Rails 4.0, include ActiveModel's forbidden
|
171
185
|
attributes protection module to get support for strong parameters.
|
172
186
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
187
|
+
```ruby
|
188
|
+
class Person
|
189
|
+
include ActiveAttr::MassAssignment
|
190
|
+
include ActiveModel::ForbiddenAttributesProtection
|
191
|
+
attr_accessor :first_name, :last_name
|
192
|
+
end
|
193
|
+
|
194
|
+
person = Person.new(ActionController::Parameters.new({
|
195
|
+
:first_name => "Chris",
|
196
|
+
:last_name => "Griego",
|
197
|
+
}).permit(:first_name))
|
198
|
+
person.first_name #=> "Chris"
|
199
|
+
person.last_name #=> nil
|
200
|
+
```
|
185
201
|
|
186
202
|
If using Rails 3.x or the [Protected Attributes gem][protected_attributes],
|
187
203
|
include ActiveModel's mass assignment security module to get support for
|
188
204
|
protected attributes, including support for mass assignment roles.
|
189
205
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
206
|
+
```ruby
|
207
|
+
class Person
|
208
|
+
include ActiveAttr::MassAssignment
|
209
|
+
include ActiveModel::MassAssignmentSecurity
|
210
|
+
attr_accessor :first_name, :last_name
|
211
|
+
attr_protected :last_name
|
212
|
+
end
|
196
213
|
|
197
|
-
|
198
|
-
|
199
|
-
|
214
|
+
person = Person.new(:first_name => "Chris", :last_name => "Griego")
|
215
|
+
person.first_name #=> "Chris"
|
216
|
+
person.last_name #=> nil
|
217
|
+
```
|
200
218
|
|
201
219
|
If using the [Strong Parameters gem][strong_parameters] with Rails 3.2,
|
202
220
|
include the forbidden attributes protection module after including
|
203
221
|
the mass assignment security module.
|
204
222
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
223
|
+
```ruby
|
224
|
+
class Person
|
225
|
+
include ActiveAttr::MassAssignment
|
226
|
+
include ActiveModel::MassAssignmentSecurity
|
227
|
+
include ActiveModel::ForbiddenAttributesProtection
|
228
|
+
end
|
229
|
+
```
|
210
230
|
|
211
231
|
### Serialization ###
|
212
232
|
|
213
233
|
The Serialization module is a shortcut for incorporating ActiveModel's
|
214
234
|
serialization functionality into your model with one include.
|
215
235
|
|
216
|
-
|
217
|
-
|
218
|
-
|
236
|
+
```ruby
|
237
|
+
class Person
|
238
|
+
include ActiveAttr::Serialization
|
239
|
+
end
|
240
|
+
```
|
219
241
|
|
220
242
|
### Model ###
|
221
243
|
|
@@ -223,9 +245,11 @@ The Model module is a shortcut for incorporating the most common model
|
|
223
245
|
functionality into your model with one include. All of the above modules
|
224
246
|
are included when you include Model.
|
225
247
|
|
226
|
-
|
227
|
-
|
228
|
-
|
248
|
+
```ruby
|
249
|
+
class Person
|
250
|
+
include ActiveAttr::Model
|
251
|
+
end
|
252
|
+
```
|
229
253
|
|
230
254
|
## Integrations ##
|
231
255
|
|
@@ -235,19 +259,23 @@ When using ActiveAttr inside a Rails application, ActiveAttr will configure
|
|
235
259
|
your models' default logger to use the Rails logger automatically. Just
|
236
260
|
include ActiveAttr in your Gemfile.
|
237
261
|
|
238
|
-
|
262
|
+
```ruby
|
263
|
+
gem "active_attr"
|
264
|
+
```
|
239
265
|
|
240
266
|
### RSpec ###
|
241
267
|
|
242
268
|
ActiveAttr comes with matchers and RSpec integration to assist you in testing
|
243
269
|
your models. The matchers also work with compatible frameworks like Shoulda.
|
244
270
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
271
|
+
```ruby
|
272
|
+
require "active_attr/rspec"
|
273
|
+
|
274
|
+
describe Person do
|
275
|
+
it do
|
276
|
+
should have_attribute(:first_name).
|
277
|
+
of_type(String).
|
278
|
+
with_default_value_of("John")
|
279
|
+
end
|
280
|
+
end
|
281
|
+
```
|