simple_model 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/simple_model/attributes.rb +12 -0
- data/lib/simple_model/version.rb +1 -1
- data/spec/attributes_spec.rb +16 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -144,7 +144,7 @@ SimpleModel is available through [Rubygems](http://rubygems.org/gems/simple_mode
|
|
144
144
|
|
145
145
|
## Notes
|
146
146
|
|
147
|
-
Release 1.2+ no longer
|
147
|
+
Release 1.2+ no longer creates instance variables, just uses the attributes hash as the data store.
|
148
148
|
|
149
149
|
## Thanks
|
150
150
|
|
@@ -73,6 +73,7 @@ module SimpleModel
|
|
73
73
|
new.set(new.send(:attributes_with_for_init,session_hash))
|
74
74
|
new
|
75
75
|
end
|
76
|
+
|
76
77
|
|
77
78
|
def defined_attributes
|
78
79
|
@defined_attributes ||= {}
|
@@ -174,6 +175,17 @@ module SimpleModel
|
|
174
175
|
end
|
175
176
|
module_eval("alias #{method_options[:alias]} #{method}")
|
176
177
|
end
|
178
|
+
|
179
|
+
# Creates alias setter and getter for the supplied attribute using the supplied alias
|
180
|
+
# See spec for example.
|
181
|
+
def alias_attribute(new_alias,attribute)
|
182
|
+
define_method(new_alias) do
|
183
|
+
self.send(attribute)
|
184
|
+
end
|
185
|
+
define_method("#{new_alias.to_s}=") do |*args, &block|
|
186
|
+
self.send("#{attribute.to_s}=",*args, &block)
|
187
|
+
end
|
188
|
+
end
|
177
189
|
end
|
178
190
|
|
179
191
|
def self.included(base)
|
data/lib/simple_model/version.rb
CHANGED
data/spec/attributes_spec.rb
CHANGED
@@ -154,6 +154,22 @@ describe SimpleModel::Attributes do
|
|
154
154
|
|
155
155
|
lambda{TestThrow.new(:boo => [])}.should raise_error(SimpleModel::ArgumentError)
|
156
156
|
end
|
157
|
+
context '#alias_attribute' do
|
158
|
+
it "should create alias for attribute" do
|
159
|
+
class TestAlias
|
160
|
+
include SimpleModel::Attributes
|
161
|
+
has_attribute :foo
|
162
|
+
alias_attribute(:bar,:foo)
|
163
|
+
end
|
164
|
+
|
165
|
+
t = TestAlias.new(:bar => "foo")
|
166
|
+
t.bar.should eql("foo")
|
167
|
+
t.foo.should eql('foo')
|
168
|
+
t = TestAlias.new(:foo => "foo")
|
169
|
+
t.bar.should eql("foo")
|
170
|
+
t.foo.should eql('foo')
|
171
|
+
end
|
172
|
+
end
|
157
173
|
|
158
174
|
end
|
159
175
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|