active_attr 0.3.0 → 0.4.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.
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +6 -1
- data/README.md +22 -2
- data/gemfiles/rails_head.gemfile +8 -0
- data/lib/active_attr.rb +1 -0
- data/lib/active_attr/attributes.rb +1 -1
- data/lib/active_attr/model.rb +28 -0
- data/lib/active_attr/version.rb +1 -1
- data/spec/functional/active_attr/attributes_spec.rb +8 -2
- data/spec/functional/active_attr/model_spec.rb +71 -0
- data/spec/unit/active_attr/basic_model_spec.rb +1 -1
- metadata +20 -16
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# ActiveAttr 0.4.0 (November 26, 2011) #
|
2
|
+
|
3
|
+
* Added Model
|
4
|
+
* Support for ActiveModel 3.2
|
5
|
+
|
1
6
|
# ActiveAttr 0.3.0 (November 26, 2011) #
|
2
7
|
|
3
8
|
* Added BlockInitialization
|
@@ -7,7 +12,7 @@
|
|
7
12
|
* Added QueryAttributes
|
8
13
|
* Added UnknownAttributeError
|
9
14
|
* Attributes now honors getters/setters when calling #read_attribute,
|
10
|
-
|
15
|
+
\#write_attribute, #[], and #[]=
|
11
16
|
* Attributes now raises DangerousAttributeError when defining an attribute
|
12
17
|
whose methods would conflict with an existing method
|
13
18
|
* Attributes now raises UnknownAttributeError when getting/setting any
|
data/README.md
CHANGED
@@ -12,6 +12,16 @@ the wheel.
|
|
12
12
|
|
13
13
|
## Modules ##
|
14
14
|
|
15
|
+
### Model ###
|
16
|
+
|
17
|
+
The Model module is a shortcut for incorporating the most common model
|
18
|
+
functionality into your model with one include. All of the following modules
|
19
|
+
are included when you include Model.
|
20
|
+
|
21
|
+
class Person
|
22
|
+
include ActiveAttr::Model
|
23
|
+
end
|
24
|
+
|
15
25
|
### Attributes ###
|
16
26
|
|
17
27
|
Including the Attributes module into your class gives you a DSL for defining
|
@@ -133,10 +143,20 @@ providing instance methods for querying your attributes
|
|
133
143
|
person.first_name? #=> true
|
134
144
|
person.last_name? #=> false
|
135
145
|
|
136
|
-
##
|
146
|
+
## Integrations ##
|
147
|
+
|
148
|
+
### Ruby on Rails ###
|
149
|
+
|
150
|
+
When using ActiveAttr inside a Rails application, ActiveAttr will configure
|
151
|
+
your models' default logger to use the Rails logger automatically. Just
|
152
|
+
include ActiveAttr in your Gemfile.
|
153
|
+
|
154
|
+
gem "active_attr"
|
155
|
+
|
156
|
+
### RSpec ###
|
137
157
|
|
138
158
|
ActiveAttr comes with matchers and RSpec integration to assist you in testing
|
139
|
-
your models.
|
159
|
+
your models. The matchers also work with compatible frameworks like Shoulda.
|
140
160
|
|
141
161
|
require "active_attr/rspec"
|
142
162
|
|
data/lib/active_attr.rb
CHANGED
@@ -29,7 +29,7 @@ module ActiveAttr
|
|
29
29
|
DEPRECATED_OBJECT_METHODS = %w(id type)
|
30
30
|
|
31
31
|
included do
|
32
|
-
attribute_method_suffix ""
|
32
|
+
attribute_method_suffix "" if attribute_method_matchers.none? { |matcher| matcher.prefix == "" && matcher.suffix == "" }
|
33
33
|
attribute_method_suffix "="
|
34
34
|
end
|
35
35
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "active_attr/basic_model"
|
2
|
+
require "active_attr/block_initialization"
|
3
|
+
require "active_attr/logger"
|
4
|
+
require "active_attr/mass_assignment_security"
|
5
|
+
require "active_attr/query_attributes"
|
6
|
+
require "active_support/concern"
|
7
|
+
|
8
|
+
module ActiveAttr
|
9
|
+
# Model is a shortcut for incorporating the most common model
|
10
|
+
# functionality into your model with one include
|
11
|
+
#
|
12
|
+
# See the included modules to learn more.
|
13
|
+
#
|
14
|
+
# @example Usage
|
15
|
+
# class Person
|
16
|
+
# include ActiveAttr::Model
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# @since 0.4.0
|
20
|
+
module Model
|
21
|
+
extend ActiveSupport::Concern
|
22
|
+
include BasicModel
|
23
|
+
include BlockInitialization
|
24
|
+
include Logger
|
25
|
+
include MassAssignmentSecurity
|
26
|
+
include QueryAttributes
|
27
|
+
end
|
28
|
+
end
|
data/lib/active_attr/version.rb
CHANGED
@@ -65,8 +65,14 @@ module ActiveAttr
|
|
65
65
|
let :model_class do
|
66
66
|
Class.new do
|
67
67
|
include Attributes
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
if defined? ActiveModel::Serializable
|
70
|
+
include ActiveModel::Serializable::JSON
|
71
|
+
include ActiveModel::Serializable::XML
|
72
|
+
else
|
73
|
+
include ActiveModel::Serializers::JSON
|
74
|
+
include ActiveModel::Serializers::Xml
|
75
|
+
end
|
70
76
|
|
71
77
|
attribute :first_name
|
72
78
|
attribute :last_name
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "active_attr/model"
|
3
|
+
|
4
|
+
module ActiveAttr
|
5
|
+
describe Model do
|
6
|
+
let :model_class do
|
7
|
+
Class.new do
|
8
|
+
include Model
|
9
|
+
|
10
|
+
attribute :first_name
|
11
|
+
attribute :last_name
|
12
|
+
|
13
|
+
attr_protected :last_name
|
14
|
+
|
15
|
+
def self.name
|
16
|
+
"Person"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { model_class.new }
|
22
|
+
it_should_behave_like "ActiveModel"
|
23
|
+
|
24
|
+
it "reads and writes attributes" do
|
25
|
+
subject.first_name = "Chris"
|
26
|
+
subject.first_name.should == "Chris"
|
27
|
+
subject.attributes["first_name"].should == "Chris"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can query attributes" do
|
31
|
+
subject.first_name?.should be_false
|
32
|
+
subject.first_name = "Chris"
|
33
|
+
subject.first_name?.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "initializes with a block that can use attributes" do
|
37
|
+
model_class.new do |person|
|
38
|
+
person.write_attribute :first_name, "Chris"
|
39
|
+
end.read_attribute(:first_name).should == "Chris"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "processes mass assignment yielding an initialization block" do
|
43
|
+
model_class.new(:first_name => "Chris") do |person|
|
44
|
+
person.first_name.should == "Chris"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has a logger" do
|
49
|
+
logger = double("logger")
|
50
|
+
model_class.logger?.should be_false
|
51
|
+
subject.logger?.should be_false
|
52
|
+
|
53
|
+
model_class.logger = logger
|
54
|
+
|
55
|
+
model_class.logger?.should be_true
|
56
|
+
model_class.logger.should == logger
|
57
|
+
subject.logger?.should be_true
|
58
|
+
subject.logger.should == logger
|
59
|
+
end
|
60
|
+
|
61
|
+
it "supports mass assignment with security" do
|
62
|
+
person = model_class.new(:first_name => "Chris", :last_name => "Griego")
|
63
|
+
person.first_name.should == "Chris"
|
64
|
+
person.last_name.should be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it "does not use strict mass assignment" do
|
68
|
+
expect { subject.assign_attributes :middle_initial => "J" }.not_to raise_error
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-27 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70208496667400 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70208496667400
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &70208496659840 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '3.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70208496659840
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70208496720580 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '1.0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70208496720580
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: factory_girl
|
50
|
-
requirement: &
|
50
|
+
requirement: &70208496732300 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '2.2'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70208496732300
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rake
|
61
|
-
requirement: &
|
61
|
+
requirement: &70208496743100 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 0.9.0
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70208496743100
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
|
-
requirement: &
|
72
|
+
requirement: &70208496750220 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '2.6'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70208496750220
|
81
81
|
description: Create plain old ruby models without reinventing the wheel.
|
82
82
|
email:
|
83
83
|
- cgriego@gmail.com
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
100
100
|
- active_attr.gemspec
|
101
|
+
- gemfiles/rails_head.gemfile
|
101
102
|
- lib/active_attr.rb
|
102
103
|
- lib/active_attr/attribute_definition.rb
|
103
104
|
- lib/active_attr/attributes.rb
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- lib/active_attr/mass_assignment_security.rb
|
112
113
|
- lib/active_attr/matchers.rb
|
113
114
|
- lib/active_attr/matchers/have_attribute_matcher.rb
|
115
|
+
- lib/active_attr/model.rb
|
114
116
|
- lib/active_attr/query_attributes.rb
|
115
117
|
- lib/active_attr/railtie.rb
|
116
118
|
- lib/active_attr/rspec.rb
|
@@ -120,6 +122,7 @@ files:
|
|
120
122
|
- lib/active_attr/version.rb
|
121
123
|
- spec/functional/active_attr/attributes_spec.rb
|
122
124
|
- spec/functional/active_attr/chainable_initialization_spec.rb
|
125
|
+
- spec/functional/active_attr/model_spec.rb
|
123
126
|
- spec/functional/active_attr/query_attributes_spec.rb
|
124
127
|
- spec/spec_helper.rb
|
125
128
|
- spec/support/active_model_lint.rb
|
@@ -154,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
157
|
version: '0'
|
155
158
|
segments:
|
156
159
|
- 0
|
157
|
-
hash:
|
160
|
+
hash: 2277450769391114254
|
158
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
162
|
none: false
|
160
163
|
requirements:
|
@@ -163,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
166
|
version: '0'
|
164
167
|
segments:
|
165
168
|
- 0
|
166
|
-
hash:
|
169
|
+
hash: 2277450769391114254
|
167
170
|
requirements: []
|
168
171
|
rubyforge_project: active_attr
|
169
172
|
rubygems_version: 1.8.10
|
@@ -173,6 +176,7 @@ summary: What ActiveModel left out
|
|
173
176
|
test_files:
|
174
177
|
- spec/functional/active_attr/attributes_spec.rb
|
175
178
|
- spec/functional/active_attr/chainable_initialization_spec.rb
|
179
|
+
- spec/functional/active_attr/model_spec.rb
|
176
180
|
- spec/functional/active_attr/query_attributes_spec.rb
|
177
181
|
- spec/spec_helper.rb
|
178
182
|
- spec/support/active_model_lint.rb
|