static_model 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.0.4 2013-03-06
2
+
3
+ * define respond_to_missing to include methods inferred from method_missing [sgtFloyd]
4
+
1
5
  == 1.0.0 2011-08-20
2
6
 
3
7
  * Remove ActiveSupport as a dependency (StaticModel has no direct dependencies now)
data/lib/static_model.rb CHANGED
@@ -5,7 +5,7 @@ require 'yaml' unless defined?(YAML)
5
5
  require 'erb' unless defined?(ERB)
6
6
 
7
7
  module StaticModel
8
- VERSION = '1.0.3'
8
+ VERSION = '1.0.4'
9
9
  end
10
10
 
11
11
  require 'static_model/active_support'
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "static_model"
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: