active_attr 0.12.0 → 0.15.1

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 (47) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yaml +160 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +33 -0
  5. data/Gemfile +5 -8
  6. data/README.md +142 -117
  7. data/active_attr.gemspec +13 -6
  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 +1 -1
  15. data/gemfiles/rails_5_1.gemfile +1 -1
  16. data/gemfiles/rails_5_2.gemfile +9 -0
  17. data/gemfiles/rails_6_0.gemfile +9 -0
  18. data/gemfiles/rails_head.gemfile +1 -1
  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 +5 -2
  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/functional/active_attr/typecasted_attributes_spec.rb +1 -1
  38. data/spec/unit/active_attr/attribute_defaults_spec.rb +8 -0
  39. data/spec/unit/active_attr/attributes_spec.rb +91 -0
  40. data/spec/unit/active_attr/query_attributes_spec.rb +4 -4
  41. data/spec/unit/active_attr/typecasting/big_decimal_typecaster_spec.rb +17 -9
  42. data/spec/unit/active_attr/typecasting/boolean_typecaster_spec.rb +7 -7
  43. data/spec/unit/active_attr/typecasting/float_typecaster_spec.rb +10 -2
  44. data/spec/unit/active_attr/typecasting/integer_typecaster_spec.rb +10 -2
  45. metadata +44 -29
  46. data/.ruby-version +0 -1
  47. data/.travis.yml +0 -83
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 02c6c69fe8a87196740e45c3e827e832b09a8eca
4
- data.tar.gz: ce44bea22a9b8d2dbc753bc9a81cee7f51b4c6da
2
+ SHA256:
3
+ metadata.gz: 643c6f5a8e69bd25697285baa018622a93aa3f6942a89dd2ffe0abc7dc6b6406
4
+ data.tar.gz: '081be1c5942fff694f85e31fa273a22e85d0e41e179f4321e3164ff6697f97cb'
5
5
  SHA512:
6
- metadata.gz: 9a13a61893450f32efa41744f7187e0cf4988359db4cf556de5175098fa9e357dd6744319e8fd43b786bcf4c9b156ea92aff74f9d26ccb1100c1821272e8a9b2
7
- data.tar.gz: 605675def174c8cd4d83d2b2b7bc9c99a57c625409cc6124f3bf163d234441c96f93cd71d78e542d4eccc52824dec4c3fae94e0d154573c088623af147797ce1
6
+ metadata.gz: 561d396771257d70ac4ac7e4d16d47c1c4cb1f59ee3da5d48bb933640253c022968120d1c53fc39cbb6fbf874d8b2531e5488922002711c8942b204d8478b0b4
7
+ data.tar.gz: ba853cbb6b519b66de4608f2614f0a12a50455e5f6eee23d6c62848d3682e69fb85c33c244a4b15d755f1c3dcda8ecf5334d0b76599c82c1ae31c6584a0bb4a7
@@ -0,0 +1,160 @@
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
+ strategy:
14
+ matrix:
15
+ ruby:
16
+ - 2.1.9
17
+ - 2.2.10
18
+ - 2.3.8
19
+ - 2.4.10
20
+ - 2.5.8
21
+ - 2.6.6
22
+ - 2.7.2
23
+ - truffleruby-head
24
+ gemfile:
25
+ - gemfiles/rails_3_0.gemfile
26
+ - gemfiles/rails_3_1.gemfile
27
+ - gemfiles/rails_3_2.gemfile
28
+ - gemfiles/rails_4_0.gemfile
29
+ - gemfiles/rails_4_1.gemfile
30
+ - gemfiles/rails_4_2.gemfile
31
+ - gemfiles/rails_5_0.gemfile
32
+ - gemfiles/rails_5_1.gemfile
33
+ - gemfiles/rails_5_2.gemfile
34
+ - gemfiles/rails_6_0.gemfile
35
+ - Gemfile
36
+ - gemfiles/rails_head.gemfile
37
+ exclude:
38
+ - ruby: 1.9.2
39
+ gemfile: gemfiles/rails_4_0.gemfile
40
+ - ruby: 1.9.2
41
+ gemfile: gemfiles/rails_4_1.gemfile
42
+ - ruby: 1.9.2
43
+ gemfile: gemfiles/rails_4_2.gemfile
44
+ - ruby: 1.9.2
45
+ gemfile: gemfiles/rails_5_0.gemfile
46
+ - ruby: 1.9.2
47
+ gemfile: gemfiles/rails_5_1.gemfile
48
+ - ruby: 1.9.2
49
+ gemfile: gemfiles/rails_5_2.gemfile
50
+ - ruby: 1.9.2
51
+ gemfile: gemfiles/rails_6_0.gemfile
52
+ - ruby: 1.9.2
53
+ gemfile: Gemfile
54
+ - ruby: 1.9.2
55
+ gemfile: gemfiles/rails_head.gemfile
56
+ - ruby: 1.9.3
57
+ gemfile: gemfiles/rails_5_0.gemfile
58
+ - ruby: 1.9.3
59
+ gemfile: gemfiles/rails_5_1.gemfile
60
+ - ruby: 1.9.3
61
+ gemfile: gemfiles/rails_5_2.gemfile
62
+ - ruby: 1.9.3
63
+ gemfile: gemfiles/rails_6_0.gemfile
64
+ - ruby: 1.9.3
65
+ gemfile: Gemfile
66
+ - ruby: 1.9.3
67
+ gemfile: gemfiles/rails_head.gemfile
68
+ - ruby: 2.0.0
69
+ gemfile: gemfiles/rails_5_0.gemfile
70
+ - ruby: 2.0.0
71
+ gemfile: gemfiles/rails_5_1.gemfile
72
+ - ruby: 2.0.0
73
+ gemfile: gemfiles/rails_5_2.gemfile
74
+ - ruby: 2.0.0
75
+ gemfile: gemfiles/rails_6_0.gemfile
76
+ - ruby: 2.0.0
77
+ gemfile: Gemfile
78
+ - ruby: 2.0.0
79
+ gemfile: gemfiles/rails_head.gemfile
80
+ - ruby: 2.1.9
81
+ gemfile: gemfiles/rails_5_0.gemfile
82
+ - ruby: 2.1.9
83
+ gemfile: gemfiles/rails_5_1.gemfile
84
+ - ruby: 2.1.9
85
+ gemfile: gemfiles/rails_5_2.gemfile
86
+ - ruby: 2.1.9
87
+ gemfile: gemfiles/rails_6_0.gemfile
88
+ - ruby: 2.1.9
89
+ gemfile: Gemfile
90
+ - ruby: 2.1.9
91
+ gemfile: gemfiles/rails_head.gemfile
92
+ - ruby: 2.2.10
93
+ gemfile: gemfiles/rails_6_0.gemfile
94
+ - ruby: 2.2.10
95
+ gemfile: Gemfile
96
+ - ruby: 2.2.10
97
+ gemfile: gemfiles/rails_head.gemfile
98
+ - ruby: 2.3.8
99
+ gemfile: gemfiles/rails_6_0.gemfile
100
+ - ruby: 2.3.8
101
+ gemfile: Gemfile
102
+ - ruby: 2.3.8
103
+ gemfile: gemfiles/rails_head.gemfile
104
+ - ruby: 2.4.10
105
+ gemfile: gemfiles/rails_6_0.gemfile
106
+ - ruby: 2.4.10
107
+ gemfile: Gemfile
108
+ - ruby: 2.4.10
109
+ gemfile: gemfiles/rails_head.gemfile
110
+ - ruby: 2.5.8
111
+ gemfile: gemfiles/rails_3_0.gemfile
112
+ - ruby: 2.6.6
113
+ gemfile: gemfiles/rails_3_0.gemfile
114
+ - ruby: 2.7.2
115
+ gemfile: gemfiles/rails_3_0.gemfile
116
+ - ruby: 2.7.2
117
+ gemfile: gemfiles/rails_3_1.gemfile
118
+ - ruby: 2.7.2
119
+ gemfile: gemfiles/rails_3_2.gemfile
120
+ - ruby: 2.7.2
121
+ gemfile: gemfiles/rails_4_0.gemfile
122
+ - ruby: 2.7.2
123
+ gemfile: gemfiles/rails_4_1.gemfile
124
+ - ruby: 2.7.2
125
+ gemfile: gemfiles/rails_4_2.gemfile
126
+ - ruby: truffleruby-head
127
+ gemfile: gemfiles/rails_3_0.gemfile
128
+ - ruby: truffleruby-head
129
+ gemfile: gemfiles/rails_3_1.gemfile
130
+ - ruby: truffleruby-head
131
+ gemfile: gemfiles/rails_3_2.gemfile
132
+ - ruby: truffleruby-head
133
+ gemfile: gemfiles/rails_4_0.gemfile
134
+ - ruby: truffleruby-head
135
+ gemfile: gemfiles/rails_4_1.gemfile
136
+ - ruby: truffleruby-head
137
+ gemfile: gemfiles/rails_4_2.gemfile
138
+ env:
139
+ Rails: ${{ matrix.rails }}
140
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
141
+ BUNDLER_VERSION: 1.17.3
142
+
143
+ steps:
144
+ - name: Checkout code
145
+ uses: actions/checkout@master
146
+ - name: Set up Ruby
147
+ uses: ruby/setup-ruby@v1
148
+ with:
149
+ ruby-version: ${{ matrix.ruby }}
150
+ - name: Set up Bundler cache
151
+ uses: actions/cache@v1
152
+ with:
153
+ path: vendor/bundle
154
+ key: ${{ runner.os }}-gems
155
+ - name: Build and run tests
156
+ run: |
157
+ gem install bundler --version ${{ env.BUNDLER_VERSION }} --no-document
158
+ bundle _${{ env.BUNDLER_VERSION }}_ config path vendor/bundle
159
+ bundle _${{ env.BUNDLER_VERSION }}_ install --jobs 4 --retry 3
160
+ bundle _${{ env.BUNDLER_VERSION }}_ 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
@@ -1,3 +1,36 @@
1
+ # ActiveAttr 0.15.1 (December 11, 2020) #
2
+
3
+ * ActiveAttr now supports Ruby 2.7
4
+ * ActiveAttr now supports Rails 6.1
5
+ * Drop support for Ruby versions below 2.1
6
+
7
+ # ActiveAttr 0.15.0 (June 12, 2019) #
8
+
9
+ * Add missing ActiveSupport require for Attributes
10
+ * Change numeric typecasters to cast nil and empty strings to nil
11
+
12
+ # ActiveAttr 0.14.0 (June 10, 2019) #
13
+
14
+ * Drop support for Ruby versions below 1.9.2
15
+ * #139 Changed Typecasting::BooleanTypecaster to cast nil and empty
16
+ strings to false (Corin Langosch)
17
+ * Attributes#inspect is now filtered based on filtered_attributes,
18
+ which defaults to `Rails.application.config.filter_parameters` in
19
+ Rails apps.
20
+ * #143 Changed Attributes to allocate less objects (Chris Grigg)
21
+ * #153 Changed HaveAttributeMatcher#with_default_value_of to support
22
+ Procs (Yoshiyuki Hirano)
23
+ * #145 Add ActiveModel::Validations::Callbacks to ActiveAttr::Model
24
+ (Kazuki BABA)
25
+
26
+ # ActiveAttr 0.13.1 (April 25, 2019) #
27
+
28
+ * ActiveAttr now supports Rails 6.0
29
+
30
+ # ActiveAttr 0.13.0 (April 6, 2019) #
31
+
32
+ * ActiveAttr now supports Ruby 2.6
33
+
1
34
  # ActiveAttr 0.12.0 (August 6, 2018) #
2
35
 
3
36
  * #167 Changed Typecasting::BooleanTypecaster to cast strings starting
data/Gemfile CHANGED
@@ -2,15 +2,14 @@ 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", ">= 5.2.0.beta1", "< 6.2"
6
+ gem "activesupport", ">= 5.2.0.beta1", "< 6.2"
7
+ gem "actionpack", ">= 5.2.0.beta1", "< 6.2"
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 "byebug"
14
13
  gem "growl"
15
14
  gem "guard"
16
15
  gem "guard-bundler"
@@ -18,8 +17,6 @@ group :development do
18
17
  gem "rb-fsevent"
19
18
  gem "rdiscount"
20
19
  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"
20
+ gem "spec_coverage", :git => "https://github.com/getaroom/spec_coverage.git"
24
21
  gem "yard"
25
22
  end
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
1
  # ActiveAttr #
2
2
 
3
- [![Build History][travis badge]][travis]
4
3
  [![Code Climate][codeclimate badge]][codeclimate]
5
4
 
6
- ActiveAttr is a set of modules that makes it easy to create plain old ruby
5
+ ActiveAttr is a set of modules that makes it easy to create plain old Ruby
7
6
  models with functionality found in ORMs, like ActiveRecord, without
8
7
  reinventing the wheel. Think of ActiveAttr as the stuff ActiveModel left out.
9
8
 
10
- ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
9
+ ActiveAttr is distributed as a Ruby gem [on rubygems.org][rubygems].
11
10
 
12
- [![Models Models Every Where][speakerdeck slide]][speakerdeck]
13
11
  [![ActiveAttr Railscast][railscast poster]][railscast]
14
12
 
15
13
  * [Slides][speakerdeck]
@@ -26,10 +24,7 @@ ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
26
24
  [rubygems]: http://rubygems.org/gems/active_attr
27
25
  [protected_attributes]: https://github.com/westonganger/protected_attributes_continued
28
26
  [strong_parameters]: https://github.com/rails/strong_parameters
29
- [speakerdeck slide]: https://speakerd.s3.amazonaws.com/presentations/4f31f1dec583b4001f008ec3/thumb_slide_0.jpg
30
27
  [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
33
28
 
34
29
  ## Modules ##
35
30
 
@@ -38,96 +33,108 @@ ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
38
33
  Including the Attributes module into your class gives you a DSL for defining
39
34
  the attributes of your model.
40
35
 
41
- class Person
42
- include ActiveAttr::Attributes
36
+ ```ruby
37
+ class Person
38
+ include ActiveAttr::Attributes
43
39
 
44
- attribute :first_name
45
- attribute :last_name
46
- end
40
+ attribute :first_name
41
+ attribute :last_name
42
+ end
47
43
 
48
- person = Person.new
49
- person.first_name = "Chris"
50
- person.last_name = "Griego"
51
- person.attributes #=> {"first_name"=>"Chris", "last_name"=>"Griego"}
44
+ person = Person.new
45
+ person.first_name = "Chris"
46
+ person.last_name = "Griego"
47
+ person.attributes #=> {"first_name"=>"Chris", "last_name"=>"Griego"}
48
+ ```
52
49
 
53
50
  #### AttributeDefaults ####
54
51
 
55
52
  Including the AttributeDefaults module into your class builds on Attributes by
56
53
  allowing defaults to be declared with attributes.
57
54
 
58
- class Person
59
- include ActiveAttr::AttributeDefaults
55
+ ```ruby
56
+ class Person
57
+ include ActiveAttr::AttributeDefaults
60
58
 
61
- attribute :first_name, :default => "John"
62
- attribute :last_name, :default => "Doe"
63
- end
59
+ attribute :first_name, :default => "John"
60
+ attribute :last_name, :default => "Doe"
61
+ end
64
62
 
65
- person = Person.new
66
- person.first_name #=> "John"
67
- person.last_name #=> "Doe"
63
+ person = Person.new
64
+ person.first_name #=> "John"
65
+ person.last_name #=> "Doe"
66
+ ```
68
67
 
69
68
  #### QueryAttributes ####
70
69
 
71
70
  Including the QueryAttributes module into your class builds on Attributes by
72
71
  providing instance methods for querying your attributes.
73
72
 
74
- class Person
75
- include ActiveAttr::QueryAttributes
73
+ ```ruby
74
+ class Person
75
+ include ActiveAttr::QueryAttributes
76
76
 
77
- attribute :first_name
78
- attribute :last_name
79
- end
77
+ attribute :first_name
78
+ attribute :last_name
79
+ end
80
80
 
81
- person = Person.new
82
- person.first_name = "Chris"
83
- person.first_name? #=> true
84
- person.last_name? #=> false
81
+ person = Person.new
82
+ person.first_name = "Chris"
83
+ person.first_name? #=> true
84
+ person.last_name? #=> false
85
+ ```
85
86
 
86
87
  #### TypecastedAttributes ####
87
88
 
88
89
  Including the TypecastedAttributes module into your class builds on Attributes
89
90
  by providing type conversion for your attributes.
90
91
 
91
- class Person
92
- include ActiveAttr::TypecastedAttributes
93
- attribute :age, :type => Integer
94
- end
92
+ ```ruby
93
+ class Person
94
+ include ActiveAttr::TypecastedAttributes
95
+ attribute :age, :type => Integer
96
+ end
95
97
 
96
- person = Person.new
97
- person.age = "29"
98
- person.age #=> 29
98
+ person = Person.new
99
+ person.age = "29"
100
+ person.age #=> 29
101
+ ```
99
102
 
100
103
  ### BasicModel ###
101
104
 
102
105
  Including the BasicModel module into your class gives you the bare minimum
103
106
  required for your model to meet the ActiveModel API requirements.
104
107
 
105
- class Person
106
- include ActiveAttr::BasicModel
107
- end
108
+ ```ruby
109
+ class Person
110
+ include ActiveAttr::BasicModel
111
+ end
108
112
 
109
- Person.model_name.plural #=> "people"
110
- person = Person.new
111
- person.valid? #=> true
112
- person.errors.full_messages #=> []
113
+ Person.model_name.plural #=> "people"
114
+ person = Person.new
115
+ person.valid? #=> true
116
+ person.errors.full_messages #=> []
117
+ ```
113
118
 
114
119
  ### BlockInitialization ###
115
120
 
116
121
  Including the BlockInitialization module into your class will yield the model
117
122
  instance to a block passed to when creating a new instance.
118
123
 
119
- class Person
120
- include ActiveAttr::BlockInitialization
121
- attr_accessor :first_name, :last_name
122
- end
124
+ ```ruby
125
+ class Person
126
+ include ActiveAttr::BlockInitialization
127
+ attr_accessor :first_name, :last_name
128
+ end
123
129
 
124
- person = Person.new do |p|
125
- p.first_name = "Chris"
126
- p.last_name = "Griego"
127
- end
130
+ person = Person.new do |p|
131
+ p.first_name = "Chris"
132
+ p.last_name = "Griego"
133
+ end
128
134
 
129
- person.first_name #=> "Chris"
130
- person.last_name #=> "Griego"
135
+ person.first_name #=> "Chris"
136
+ person.last_name #=> "Griego"
137
+ ```
131
138
 
132
139
  ### Logger ###
133
140
 
@@ -137,18 +144,20 @@ be configured on an instance, subclass, class, parent class, and globally by
137
144
  setting ActiveAttr::Logger.logger. When using Rails, the Rails framework
138
145
  logger will be configured by default.
139
146
 
140
- class Person
141
- include ActiveAttr::Logger
142
- end
147
+ ```ruby
148
+ class Person
149
+ include ActiveAttr::Logger
150
+ end
143
151
 
144
- Person.logger = Logger.new(STDOUT)
145
- Person.logger? #=> true
146
- Person.logger.info "Logging an informational message"
152
+ Person.logger = Logger.new(STDOUT)
153
+ Person.logger? #=> true
154
+ Person.logger.info "Logging an informational message"
147
155
 
148
- person = Person.new
149
- person.logger? #=> true
150
- person.logger = Logger.new(STDERR)
151
- person.logger.warn "Logging a warning message"
156
+ person = Person.new
157
+ person.logger? #=> true
158
+ person.logger = Logger.new(STDERR)
159
+ person.logger.warn "Logging a warning message"
160
+ ```
152
161
 
153
162
  ### MassAssignment ###
154
163
 
@@ -156,66 +165,76 @@ Including the MassAssignment module into your class gives you methods for bulk
156
165
  initializing and updating the attributes of your model. Any unknown attributes
157
166
  are silently ignored.
158
167
 
159
- class Person
160
- include ActiveAttr::MassAssignment
161
- attr_accessor :first_name, :last_name, :age
162
- end
168
+ ```ruby
169
+ class Person
170
+ include ActiveAttr::MassAssignment
171
+ attr_accessor :first_name, :last_name, :age
172
+ end
163
173
 
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"
174
+ person = Person.new(:first_name => "Christopher", :last_name => "Griego")
175
+ person.attributes = { :first_name => "Chris", :age => 21 }
176
+ person.first_name #=> "Chris"
177
+ person.last_name #=> "Griego"
178
+ ```
168
179
 
169
180
  MassAssignment supports mass assignment security/sanitization if a sanitizer
170
181
  is included in the model. If using Rails 4.0, include ActiveModel's forbidden
171
182
  attributes protection module to get support for strong parameters.
172
183
 
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
184
+ ```ruby
185
+ class Person
186
+ include ActiveAttr::MassAssignment
187
+ include ActiveModel::ForbiddenAttributesProtection
188
+ attr_accessor :first_name, :last_name
189
+ end
190
+
191
+ person = Person.new(ActionController::Parameters.new({
192
+ :first_name => "Chris",
193
+ :last_name => "Griego",
194
+ }).permit(:first_name))
195
+ person.first_name #=> "Chris"
196
+ person.last_name #=> nil
197
+ ```
185
198
 
186
199
  If using Rails 3.x or the [Protected Attributes gem][protected_attributes],
187
200
  include ActiveModel's mass assignment security module to get support for
188
201
  protected attributes, including support for mass assignment roles.
189
202
 
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
203
+ ```ruby
204
+ class Person
205
+ include ActiveAttr::MassAssignment
206
+ include ActiveModel::MassAssignmentSecurity
207
+ attr_accessor :first_name, :last_name
208
+ attr_protected :last_name
209
+ end
196
210
 
197
- person = Person.new(:first_name => "Chris", :last_name => "Griego")
198
- person.first_name #=> "Chris"
199
- person.last_name #=> nil
211
+ person = Person.new(:first_name => "Chris", :last_name => "Griego")
212
+ person.first_name #=> "Chris"
213
+ person.last_name #=> nil
214
+ ```
200
215
 
201
216
  If using the [Strong Parameters gem][strong_parameters] with Rails 3.2,
202
217
  include the forbidden attributes protection module after including
203
218
  the mass assignment security module.
204
219
 
205
- class Person
206
- include ActiveAttr::MassAssignment
207
- include ActiveModel::MassAssignmentSecurity
208
- include ActiveModel::ForbiddenAttributesProtection
209
- end
220
+ ```ruby
221
+ class Person
222
+ include ActiveAttr::MassAssignment
223
+ include ActiveModel::MassAssignmentSecurity
224
+ include ActiveModel::ForbiddenAttributesProtection
225
+ end
226
+ ```
210
227
 
211
228
  ### Serialization ###
212
229
 
213
230
  The Serialization module is a shortcut for incorporating ActiveModel's
214
231
  serialization functionality into your model with one include.
215
232
 
216
- class Person
217
- include ActiveAttr::Serialization
218
- end
233
+ ```ruby
234
+ class Person
235
+ include ActiveAttr::Serialization
236
+ end
237
+ ```
219
238
 
220
239
  ### Model ###
221
240
 
@@ -223,9 +242,11 @@ The Model module is a shortcut for incorporating the most common model
223
242
  functionality into your model with one include. All of the above modules
224
243
  are included when you include Model.
225
244
 
226
- class Person
227
- include ActiveAttr::Model
228
- end
245
+ ```ruby
246
+ class Person
247
+ include ActiveAttr::Model
248
+ end
249
+ ```
229
250
 
230
251
  ## Integrations ##
231
252
 
@@ -235,19 +256,23 @@ When using ActiveAttr inside a Rails application, ActiveAttr will configure
235
256
  your models' default logger to use the Rails logger automatically. Just
236
257
  include ActiveAttr in your Gemfile.
237
258
 
238
- gem "active_attr"
259
+ ```ruby
260
+ gem "active_attr"
261
+ ```
239
262
 
240
263
  ### RSpec ###
241
264
 
242
265
  ActiveAttr comes with matchers and RSpec integration to assist you in testing
243
266
  your models. The matchers also work with compatible frameworks like Shoulda.
244
267
 
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
268
+ ```ruby
269
+ require "active_attr/rspec"
270
+
271
+ describe Person do
272
+ it do
273
+ should have_attribute(:first_name).
274
+ of_type(String).
275
+ with_default_value_of("John")
276
+ end
277
+ end
278
+ ```