static_model 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/static_model.rb +1 -1
- data/lib/static_model/base.rb +14 -0
- data/static_model.gemspec +1 -1
- data/test/test_helper.rb +4 -0
- data/test/test_static_model.rb +24 -0
- metadata +1 -1
data/History.txt
CHANGED
data/lib/static_model.rb
CHANGED
data/lib/static_model/base.rb
CHANGED
@@ -209,6 +209,15 @@ module StaticModel
|
|
209
209
|
end
|
210
210
|
super
|
211
211
|
end
|
212
|
+
|
213
|
+
def respond_to_missing?(meth, *args)
|
214
|
+
meth_name = meth.to_s
|
215
|
+
if meth_name =~ /^find_(all_by|first_by|last_by|by)_(.+)/
|
216
|
+
attribute_name = meth_name.gsub(/^find_(all_by|first_by|last_by|by)_/, '')
|
217
|
+
return true if has_attribute?(attribute_name)
|
218
|
+
end
|
219
|
+
class_attributes.has_key?(meth_name) || super
|
220
|
+
end
|
212
221
|
end
|
213
222
|
|
214
223
|
protected
|
@@ -235,5 +244,10 @@ module StaticModel
|
|
235
244
|
super
|
236
245
|
end
|
237
246
|
|
247
|
+
def respond_to_missing?(meth, *args)
|
248
|
+
attribute_name = meth.to_s.gsub(/=$/,'')
|
249
|
+
has_attribute?(attribute_name) || super
|
250
|
+
end
|
251
|
+
|
238
252
|
end
|
239
253
|
end
|
data/static_model.gemspec
CHANGED
data/test/test_helper.rb
CHANGED
@@ -12,6 +12,10 @@ class Book < StaticModel::Base
|
|
12
12
|
attribute :read, :default => false, :freeze => true
|
13
13
|
end
|
14
14
|
|
15
|
+
class BookWithInferredAttributes < StaticModel::Base
|
16
|
+
set_data_file File.join(File.dirname(__FILE__), 'data', 'books.yml')
|
17
|
+
end
|
18
|
+
|
15
19
|
unless defined?(ActiveRecord::Base)
|
16
20
|
module ActiveRecord
|
17
21
|
class Base
|
data/test/test_static_model.rb
CHANGED
@@ -87,6 +87,30 @@ class TestStaticModel < Test::Unit::TestCase
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
context "respond_to?" do
|
91
|
+
context 'with attributes explicitly set' do
|
92
|
+
setup do
|
93
|
+
@book = Book[1]
|
94
|
+
end
|
95
|
+
|
96
|
+
should 'respond_to? attribute methods' do
|
97
|
+
assert @book.respond_to?(:rating)
|
98
|
+
assert @book.respond_to?(:rating=)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with attributes inferred from data file' do
|
103
|
+
setup do
|
104
|
+
@book = BookWithInferredAttributes[1]
|
105
|
+
end
|
106
|
+
|
107
|
+
should 'respond_to? attribute methods' do
|
108
|
+
assert @book.respond_to?(:rating)
|
109
|
+
assert @book.respond_to?(:rating=)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
90
114
|
end
|
91
115
|
|
92
116
|
context "on the class" do
|