active_attr 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of active_attr might be problematic. Click here for more details.

Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +0 -17
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +4 -5
  6. data/README.md +140 -112
  7. data/active_attr.gemspec +8 -1
  8. data/gemfiles/rails_3_0.gemfile +0 -4
  9. data/gemfiles/rails_3_1.gemfile +0 -4
  10. data/gemfiles/rails_3_2.gemfile +0 -4
  11. data/gemfiles/rails_4_0.gemfile +1 -1
  12. data/gemfiles/rails_4_1.gemfile +1 -1
  13. data/gemfiles/rails_4_2.gemfile +1 -1
  14. data/gemfiles/rails_5_0.gemfile +1 -1
  15. data/gemfiles/rails_5_1.gemfile +1 -1
  16. data/gemfiles/rails_5_2.gemfile +1 -1
  17. data/gemfiles/rails_head.gemfile +1 -1
  18. data/lib/active_attr.rb +1 -1
  19. data/lib/active_attr/attributes.rb +62 -9
  20. data/lib/active_attr/chainable_initialization.rb +2 -6
  21. data/lib/active_attr/logger.rb +1 -1
  22. data/lib/active_attr/mass_assignment.rb +2 -2
  23. data/lib/active_attr/matchers/have_attribute_matcher.rb +1 -1
  24. data/lib/active_attr/model.rb +1 -0
  25. data/lib/active_attr/query_attributes.rb +1 -1
  26. data/lib/active_attr/railtie.rb +5 -0
  27. data/lib/active_attr/typecasting/boolean_typecaster.rb +8 -0
  28. data/lib/active_attr/version.rb +1 -1
  29. data/spec/functional/active_attr/attributes_spec.rb +8 -8
  30. data/spec/functional/active_attr/matchers/have_attribute_matcher_spec.rb +48 -0
  31. data/spec/functional/active_attr/model_spec.rb +47 -0
  32. data/spec/unit/active_attr/attribute_defaults_spec.rb +8 -0
  33. data/spec/unit/active_attr/attributes_spec.rb +91 -0
  34. data/spec/unit/active_attr/typecasting/big_decimal_typecaster_spec.rb +4 -0
  35. data/spec/unit/active_attr/typecasting/boolean_typecaster_spec.rb +3 -3
  36. metadata +27 -13
  37. data/.ruby-version +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 96b66cfd6c4ba38a961eb353217d0d79d6465559
4
- data.tar.gz: 475cd75d910ddc57541f1d9d36ecfe51f775ef61
2
+ SHA256:
3
+ metadata.gz: 27d7a6a18d57befed3918f2bfff542bd99d9ef58fa7cfe68b028b6165cc2e001
4
+ data.tar.gz: 050735d5e29e679f140f9521452dd75266116efd94c9b72a6215f4bb52834aff
5
5
  SHA512:
6
- metadata.gz: 02c53088df97f8205e01df057b1bccd52d21d4f00faee1aa92fd2da7bce0de9ec89ead63045c350d961195c2f4c424e43073f6dd97c87457c4feaed8e3a84c9d
7
- data.tar.gz: 4a35b87cfb20d2e0573eadd0e222e730a1e66ecc80c32499fcbd8800f952d698c98122c2634bf4d7731b3a01201f7ef50977f8fb9b17e8f77cf6abafa1785638
6
+ metadata.gz: '0648dc4bb4168744604929bdc7f32d3e5ba2a5ffea45e3e7c4c27f6cfa3ce2f7aafe220b09f0cb239363bf4197ae7bfde959c52173fed65d5fbfd2f4cdd7efcc'
7
+ data.tar.gz: 92d9884debc077a14e90627eeef4fed79fb927467d1934cc7739198541f27b9da380cfcf2de3518c5c111113a6fbc9dbd1a83b3af413d421252a2829da5f4de5
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .rvmrc
4
4
  .yardoc
5
5
  /.ruby-gemset
6
+ /.ruby-version
6
7
  coverage
7
8
  doc
8
9
  Gemfile.lock
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", :group => :test
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", :platforms => :mri_19
13
- gem "byebug", :platforms => [:mri_20, :mri_21, :mri_22, :mri_23, :mri_24]
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 "ruby-debug", :platforms => :mri_18
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
- class Person
42
- include ActiveAttr::Attributes
39
+ ```ruby
40
+ class Person
41
+ include ActiveAttr::Attributes
43
42
 
44
- attribute :first_name
45
- attribute :last_name
46
- end
43
+ attribute :first_name
44
+ attribute :last_name
45
+ end
47
46
 
48
- person = Person.new
49
- person.first_name = "Chris"
50
- person.last_name = "Griego"
51
- person.attributes #=> {"first_name"=>"Chris", "last_name"=>"Griego"}
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
- class Person
59
- include ActiveAttr::AttributeDefaults
58
+ ```ruby
59
+ class Person
60
+ include ActiveAttr::AttributeDefaults
60
61
 
61
- attribute :first_name, :default => "John"
62
- attribute :last_name, :default => "Doe"
63
- end
62
+ attribute :first_name, :default => "John"
63
+ attribute :last_name, :default => "Doe"
64
+ end
64
65
 
65
- person = Person.new
66
- person.first_name #=> "John"
67
- person.last_name #=> "Doe"
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
- class Person
75
- include ActiveAttr::QueryAttributes
76
+ ```ruby
77
+ class Person
78
+ include ActiveAttr::QueryAttributes
76
79
 
77
- attribute :first_name
78
- attribute :last_name
79
- end
80
+ attribute :first_name
81
+ attribute :last_name
82
+ end
80
83
 
81
- person = Person.new
82
- person.first_name = "Chris"
83
- person.first_name? #=> true
84
- person.last_name? #=> false
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
- class Person
92
- include ActiveAttr::TypecastedAttributes
93
- attribute :age, :type => Integer
94
- end
95
+ ```ruby
96
+ class Person
97
+ include ActiveAttr::TypecastedAttributes
98
+ attribute :age, :type => Integer
99
+ end
95
100
 
96
- person = Person.new
97
- person.age = "29"
98
- person.age #=> 29
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
- class Person
106
- include ActiveAttr::BasicModel
107
- end
111
+ ```ruby
112
+ class Person
113
+ include ActiveAttr::BasicModel
114
+ end
108
115
 
109
- Person.model_name.plural #=> "people"
110
- person = Person.new
111
- person.valid? #=> true
112
- person.errors.full_messages #=> []
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
- class Person
120
- include ActiveAttr::BlockInitialization
121
- attr_accessor :first_name, :last_name
122
- end
127
+ ```ruby
128
+ class Person
129
+ include ActiveAttr::BlockInitialization
130
+ attr_accessor :first_name, :last_name
131
+ end
123
132
 
124
- person = Person.new do |p|
125
- p.first_name = "Chris"
126
- p.last_name = "Griego"
127
- end
133
+ person = Person.new do |p|
134
+ p.first_name = "Chris"
135
+ p.last_name = "Griego"
136
+ end
128
137
 
129
- person.first_name #=> "Chris"
130
- person.last_name #=> "Griego"
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
- class Person
141
- include ActiveAttr::Logger
142
- end
150
+ ```ruby
151
+ class Person
152
+ include ActiveAttr::Logger
153
+ end
143
154
 
144
- Person.logger = Logger.new(STDOUT)
145
- Person.logger? #=> true
146
- Person.logger.info "Logging an informational message"
155
+ Person.logger = Logger.new(STDOUT)
156
+ Person.logger? #=> true
157
+ Person.logger.info "Logging an informational message"
147
158
 
148
- person = Person.new
149
- person.logger? #=> true
150
- person.logger = Logger.new(STDERR)
151
- person.logger.warn "Logging a warning message"
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
- class Person
160
- include ActiveAttr::MassAssignment
161
- attr_accessor :first_name, :last_name, :age
162
- end
171
+ ```ruby
172
+ class Person
173
+ include ActiveAttr::MassAssignment
174
+ attr_accessor :first_name, :last_name, :age
175
+ end
163
176
 
164
- person = Person.new(:first_name => "Christopher", :last_name => "Griego")
165
- person.attributes = { :first_name => "Chris", :age => 21 }
166
- person.first_name #=> "Chris"
167
- person.last_name #=> "Griego"
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
- class Person
174
- include ActiveAttr::MassAssignment
175
- include ActiveModel::ForbiddenAttributesProtection
176
- attr_accessor :first_name, :last_name
177
- end
178
-
179
- person = Person.new(ActionController::Parameters.new({
180
- :first_name => "Chris",
181
- :last_name => "Griego",
182
- }).permit(:first_name))
183
- person.first_name #=> "Chris"
184
- person.last_name #=> nil
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
- class Person
191
- include ActiveAttr::MassAssignment
192
- include ActiveModel::MassAssignmentSecurity
193
- attr_accessor :first_name, :last_name
194
- attr_protected :last_name
195
- end
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
- person = Person.new(:first_name => "Chris", :last_name => "Griego")
198
- person.first_name #=> "Chris"
199
- person.last_name #=> nil
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
- class Person
206
- include ActiveAttr::MassAssignment
207
- include ActiveModel::MassAssignmentSecurity
208
- include ActiveModel::ForbiddenAttributesProtection
209
- end
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
- class Person
217
- include ActiveAttr::Serialization
218
- end
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
- class Person
227
- include ActiveAttr::Model
228
- end
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
- gem "active_attr"
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
- require "active_attr/rspec"
246
-
247
- describe Person do
248
- it do
249
- should have_attribute(:first_name).
250
- of_type(String).
251
- with_default_value_of("John")
252
- end
253
- end
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
+ ```