active_attr 0.13.0 → 0.15.2

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 (45) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yaml +180 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +34 -0
  5. data/Gemfile +6 -8
  6. data/README.md +145 -117
  7. data/active_attr.gemspec +14 -7
  8. data/gemfiles/rails_3_0.gemfile +0 -4
  9. data/gemfiles/rails_3_1.gemfile +1 -8
  10. data/gemfiles/rails_3_2.gemfile +1 -12
  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 +2 -1
  15. data/gemfiles/rails_5_1.gemfile +2 -1
  16. data/gemfiles/rails_5_2.gemfile +10 -0
  17. data/gemfiles/rails_6_0.gemfile +10 -0
  18. data/gemfiles/rails_head.gemfile +3 -2
  19. data/lib/active_attr.rb +1 -1
  20. data/lib/active_attr/attributes.rb +63 -9
  21. data/lib/active_attr/chainable_initialization.rb +2 -6
  22. data/lib/active_attr/logger.rb +1 -1
  23. data/lib/active_attr/mass_assignment.rb +2 -2
  24. data/lib/active_attr/matchers/have_attribute_matcher.rb +1 -1
  25. data/lib/active_attr/model.rb +1 -0
  26. data/lib/active_attr/query_attributes.rb +1 -1
  27. data/lib/active_attr/railtie.rb +5 -0
  28. data/lib/active_attr/typecasting/big_decimal_typecaster.rb +3 -0
  29. data/lib/active_attr/typecasting/boolean_typecaster.rb +8 -0
  30. data/lib/active_attr/typecasting/float_typecaster.rb +3 -1
  31. data/lib/active_attr/typecasting/integer_typecaster.rb +3 -1
  32. data/lib/active_attr/version.rb +1 -1
  33. data/spec/functional/active_attr/attributes_spec.rb +8 -40
  34. data/spec/functional/active_attr/mass_assignment_spec.rb +2 -2
  35. data/spec/functional/active_attr/matchers/have_attribute_matcher_spec.rb +48 -0
  36. data/spec/functional/active_attr/model_spec.rb +47 -0
  37. data/spec/unit/active_attr/attribute_defaults_spec.rb +8 -0
  38. data/spec/unit/active_attr/attributes_spec.rb +91 -0
  39. data/spec/unit/active_attr/typecasting/big_decimal_typecaster_spec.rb +11 -3
  40. data/spec/unit/active_attr/typecasting/boolean_typecaster_spec.rb +3 -3
  41. data/spec/unit/active_attr/typecasting/float_typecaster_spec.rb +10 -2
  42. data/spec/unit/active_attr/typecasting/integer_typecaster_spec.rb +10 -2
  43. metadata +48 -33
  44. data/.ruby-version +0 -1
  45. data/.travis.yml +0 -94
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 51278f667fa7e613cd46655c1f19970f66740fb0
4
- data.tar.gz: cb9db1fa72766751d76ed10ac783bb301f3f7ca8
2
+ SHA256:
3
+ metadata.gz: 13cccbd932517dff946d30e95472d0be860ee9ae904fb23c2ec51218b8d53bf1
4
+ data.tar.gz: d6a7add449df97e240d2e6ecef52d50ae790a6c8b1929b55bfd8bab31435c5b2
5
5
  SHA512:
6
- metadata.gz: 468c65ec0ee598cd5371e1fb176edb280e6ac06d8d81a66c7a3660062e431633e01f3e2ea597c6a115ab983bfc98e2d04c8b071d0792f744380bfc5048b4ddb9
7
- data.tar.gz: c44da46b5e82fa1dbcd2b9ca698a4f800c5a488319b316cc2f63605449e123cb20d4bbdd64f4f6abe0f967997afe9cdce60cdfd611212937c323ef188549e108
6
+ metadata.gz: 1420ec710d5245ac17ec4c4afa56745d37b0fe6fabf36767de00ac8e4a4e43248161a4e631054535aaaa5c2f61df5b6057068f0ed3f45a52293f9e904b0e92b3
7
+ data.tar.gz: 10a86931d030166c531af1552223a6fc96803c7259fd1e61069f2bbc3ab5d8f70eb6bfb9e9cc619ed6772bb65ad7d6863dd3d4d681e9ae01241238b79a739863
@@ -0,0 +1,180 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ name: Ruby ${{ matrix.ruby }} with ${{ matrix.gemfile }}
12
+ runs-on: ubuntu-latest
13
+ continue-on-error: ${{ contains(matrix.ruby, 'head') || contains(matrix.gemfile, 'head') }}
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ ruby:
18
+ - 2.1.9
19
+ - 2.2.10
20
+ - 2.3.8
21
+ - 2.4.10
22
+ - 2.5.8
23
+ - 2.6.6
24
+ - 2.7.2
25
+ - 3.0.0
26
+ - truffleruby-head
27
+ gemfile:
28
+ - gemfiles/rails_3_0.gemfile
29
+ - gemfiles/rails_3_1.gemfile
30
+ - gemfiles/rails_3_2.gemfile
31
+ - gemfiles/rails_4_0.gemfile
32
+ - gemfiles/rails_4_1.gemfile
33
+ - gemfiles/rails_4_2.gemfile
34
+ - gemfiles/rails_5_0.gemfile
35
+ - gemfiles/rails_5_1.gemfile
36
+ - gemfiles/rails_5_2.gemfile
37
+ - gemfiles/rails_6_0.gemfile
38
+ - Gemfile
39
+ - gemfiles/rails_head.gemfile
40
+ exclude:
41
+ - ruby: 1.9.2
42
+ gemfile: gemfiles/rails_4_0.gemfile
43
+ - ruby: 1.9.2
44
+ gemfile: gemfiles/rails_4_1.gemfile
45
+ - ruby: 1.9.2
46
+ gemfile: gemfiles/rails_4_2.gemfile
47
+ - ruby: 1.9.2
48
+ gemfile: gemfiles/rails_5_0.gemfile
49
+ - ruby: 1.9.2
50
+ gemfile: gemfiles/rails_5_1.gemfile
51
+ - ruby: 1.9.2
52
+ gemfile: gemfiles/rails_5_2.gemfile
53
+ - ruby: 1.9.2
54
+ gemfile: gemfiles/rails_6_0.gemfile
55
+ - ruby: 1.9.2
56
+ gemfile: Gemfile
57
+ - ruby: 1.9.2
58
+ gemfile: gemfiles/rails_head.gemfile
59
+ - ruby: 1.9.3
60
+ gemfile: gemfiles/rails_5_0.gemfile
61
+ - ruby: 1.9.3
62
+ gemfile: gemfiles/rails_5_1.gemfile
63
+ - ruby: 1.9.3
64
+ gemfile: gemfiles/rails_5_2.gemfile
65
+ - ruby: 1.9.3
66
+ gemfile: gemfiles/rails_6_0.gemfile
67
+ - ruby: 1.9.3
68
+ gemfile: Gemfile
69
+ - ruby: 1.9.3
70
+ gemfile: gemfiles/rails_head.gemfile
71
+ - ruby: 2.0.0
72
+ gemfile: gemfiles/rails_5_0.gemfile
73
+ - ruby: 2.0.0
74
+ gemfile: gemfiles/rails_5_1.gemfile
75
+ - ruby: 2.0.0
76
+ gemfile: gemfiles/rails_5_2.gemfile
77
+ - ruby: 2.0.0
78
+ gemfile: gemfiles/rails_6_0.gemfile
79
+ - ruby: 2.0.0
80
+ gemfile: Gemfile
81
+ - ruby: 2.0.0
82
+ gemfile: gemfiles/rails_head.gemfile
83
+ - ruby: 2.1.9
84
+ gemfile: gemfiles/rails_5_0.gemfile
85
+ - ruby: 2.1.9
86
+ gemfile: gemfiles/rails_5_1.gemfile
87
+ - ruby: 2.1.9
88
+ gemfile: gemfiles/rails_5_2.gemfile
89
+ - ruby: 2.1.9
90
+ gemfile: gemfiles/rails_6_0.gemfile
91
+ - ruby: 2.1.9
92
+ gemfile: Gemfile
93
+ - ruby: 2.1.9
94
+ gemfile: gemfiles/rails_head.gemfile
95
+ - ruby: 2.2.10
96
+ gemfile: gemfiles/rails_6_0.gemfile
97
+ - ruby: 2.2.10
98
+ gemfile: Gemfile
99
+ - ruby: 2.2.10
100
+ gemfile: gemfiles/rails_head.gemfile
101
+ - ruby: 2.3.8
102
+ gemfile: gemfiles/rails_6_0.gemfile
103
+ - ruby: 2.3.8
104
+ gemfile: Gemfile
105
+ - ruby: 2.3.8
106
+ gemfile: gemfiles/rails_head.gemfile
107
+ - ruby: 2.4.10
108
+ gemfile: gemfiles/rails_6_0.gemfile
109
+ - ruby: 2.4.10
110
+ gemfile: Gemfile
111
+ - ruby: 2.4.10
112
+ gemfile: gemfiles/rails_head.gemfile
113
+ - ruby: 2.5.8
114
+ gemfile: gemfiles/rails_3_0.gemfile
115
+ - ruby: 2.5.8
116
+ gemfile: gemfiles/rails_head.gemfile
117
+ - ruby: 2.6.6
118
+ gemfile: gemfiles/rails_3_0.gemfile
119
+ - ruby: 2.6.6
120
+ gemfile: gemfiles/rails_head.gemfile
121
+ - ruby: 2.7.2
122
+ gemfile: gemfiles/rails_3_0.gemfile
123
+ - ruby: 2.7.2
124
+ gemfile: gemfiles/rails_3_1.gemfile
125
+ - ruby: 2.7.2
126
+ gemfile: gemfiles/rails_3_2.gemfile
127
+ - ruby: 2.7.2
128
+ gemfile: gemfiles/rails_4_0.gemfile
129
+ - ruby: 2.7.2
130
+ gemfile: gemfiles/rails_4_1.gemfile
131
+ - ruby: 2.7.2
132
+ gemfile: gemfiles/rails_4_2.gemfile
133
+ - ruby: 3.0.0
134
+ gemfile: gemfiles/rails_3_0.gemfile
135
+ - ruby: 3.0.0
136
+ gemfile: gemfiles/rails_3_1.gemfile
137
+ - ruby: 3.0.0
138
+ gemfile: gemfiles/rails_3_2.gemfile
139
+ - ruby: 3.0.0
140
+ gemfile: gemfiles/rails_4_0.gemfile
141
+ - ruby: 3.0.0
142
+ gemfile: gemfiles/rails_4_1.gemfile
143
+ - ruby: 3.0.0
144
+ gemfile: gemfiles/rails_4_2.gemfile
145
+ - ruby: 3.0.0
146
+ gemfile: gemfiles/rails_5_0.gemfile
147
+ - ruby: 3.0.0
148
+ gemfile: gemfiles/rails_5_1.gemfile
149
+ - ruby: 3.0.0
150
+ gemfile: gemfiles/rails_5_2.gemfile
151
+ - ruby: truffleruby-head
152
+ gemfile: gemfiles/rails_3_0.gemfile
153
+ - ruby: truffleruby-head
154
+ gemfile: gemfiles/rails_3_1.gemfile
155
+ - ruby: truffleruby-head
156
+ gemfile: gemfiles/rails_3_2.gemfile
157
+ - ruby: truffleruby-head
158
+ gemfile: gemfiles/rails_4_0.gemfile
159
+ - ruby: truffleruby-head
160
+ gemfile: gemfiles/rails_4_1.gemfile
161
+ - ruby: truffleruby-head
162
+ gemfile: gemfiles/rails_4_2.gemfile
163
+ env:
164
+ Rails: ${{ matrix.rails }}
165
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
166
+
167
+ steps:
168
+ - name: Checkout code
169
+ uses: actions/checkout@master
170
+ - name: Nokogiri support for TruffleRuby
171
+ run: sudo apt-get -yqq install libxml2-dev libxslt-dev
172
+ if: ${{ matrix.ruby == 'truffleruby-head' }}
173
+ - name: Set up Ruby
174
+ uses: ruby/setup-ruby@v1
175
+ with:
176
+ ruby-version: ${{ matrix.ruby }}
177
+ bundler: 1
178
+ bundler-cache: true
179
+ - name: Run tests
180
+ run: bundle exec rake --trace
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/CHANGELOG.md CHANGED
@@ -1,3 +1,37 @@
1
+ # ActiveAttr 0.15.2 (February 17, 2021)
2
+
3
+ * ActiveAttr now supports Ruby 3.0
4
+ * Allow unreleased versions of Rails 7.0
5
+
6
+ # ActiveAttr 0.15.1 (December 11, 2020) #
7
+
8
+ * ActiveAttr now supports Ruby 2.7
9
+ * ActiveAttr now supports Rails 6.1
10
+ * Drop support for Ruby versions below 2.1
11
+
12
+ # ActiveAttr 0.15.0 (June 12, 2019) #
13
+
14
+ * Add missing ActiveSupport require for Attributes
15
+ * Change numeric typecasters to cast nil and empty strings to nil
16
+
17
+ # ActiveAttr 0.14.0 (June 10, 2019) #
18
+
19
+ * Drop support for Ruby versions below 1.9.2
20
+ * #139 Changed Typecasting::BooleanTypecaster to cast nil and empty
21
+ strings to false (Corin Langosch)
22
+ * Attributes#inspect is now filtered based on filtered_attributes,
23
+ which defaults to `Rails.application.config.filter_parameters` in
24
+ Rails apps.
25
+ * #143 Changed Attributes to allocate less objects (Chris Grigg)
26
+ * #153 Changed HaveAttributeMatcher#with_default_value_of to support
27
+ Procs (Yoshiyuki Hirano)
28
+ * #145 Add ActiveModel::Validations::Callbacks to ActiveAttr::Model
29
+ (Kazuki BABA)
30
+
31
+ # ActiveAttr 0.13.1 (April 25, 2019) #
32
+
33
+ * ActiveAttr now supports Rails 6.0
34
+
1
35
  # ActiveAttr 0.13.0 (April 6, 2019) #
2
36
 
3
37
  * ActiveAttr now supports Ruby 2.6
data/Gemfile CHANGED
@@ -2,15 +2,15 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec :development_group => :test
4
4
 
5
- gem "activemodel", ">= 5.2.0.beta1", "< 6.0"
6
- gem "activesupport", ">= 5.2.0.beta1", "< 6.0"
7
- gem "actionpack", ">= 5.2.0.beta1", "< 6.0", :group => :test
5
+ gem "activemodel", "~> 6.1.0"
6
+ gem "activesupport", "~> 6.1.0"
7
+ gem "actionpack", "~> 6.1.0"
8
8
  gem "activemodel-serializers-xml", :group => :test
9
+ gem "rexml", :group => :test
9
10
  gem "protected_attributes_continued", :group => :test
10
11
 
11
12
  group :development do
12
- gem "debugger", :platforms => :mri_19
13
- gem "byebug", :platforms => [:mri_20, :mri_21, :mri_22, :mri_23, :mri_24]
13
+ gem "byebug"
14
14
  gem "growl"
15
15
  gem "guard"
16
16
  gem "guard-bundler"
@@ -18,8 +18,6 @@ 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"
23
- gem "travis"
21
+ gem "spec_coverage", :git => "https://github.com/getaroom/spec_coverage.git"
24
22
  gem "yard"
25
23
  end
data/README.md CHANGED
@@ -1,15 +1,14 @@
1
1
  # ActiveAttr #
2
2
 
3
- [![Build History][travis badge]][travis]
3
+ [![Build History][build badge]][build history]
4
4
  [![Code Climate][codeclimate badge]][codeclimate]
5
5
 
6
- ActiveAttr is a set of modules that makes it easy to create plain old ruby
6
+ ActiveAttr is a set of modules that makes it easy to create plain old Ruby
7
7
  models with functionality found in ORMs, like ActiveRecord, without
8
8
  reinventing the wheel. Think of ActiveAttr as the stuff ActiveModel left out.
9
9
 
10
- ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
10
+ ActiveAttr is distributed as a Ruby gem [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,10 +25,9 @@ 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
- [travis badge]: https://secure.travis-ci.org/cgriego/active_attr.svg?branch=master
32
- [travis]: http://travis-ci.org/cgriego/active_attr
29
+ [build badge]: https://github.com/cgriego/active_attr/workflows/Test/badge.svg?event=push
30
+ [build history]: https://github.com/cgriego/active_attr/actions?query=workflow%3ATest
33
31
 
34
32
  ## Modules ##
35
33
 
@@ -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
+ ```