static_model 0.2.3 → 0.2.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 +5 -0
- data/lib/static_model/base.rb +8 -5
- data/lib/static_model.rb +1 -1
- data/static_model.gemspec +2 -2
- data/test/data/books.yml +0 -1
- data/test/test_static_model.rb +11 -0
- metadata +2 -2
data/History.txt
CHANGED
data/lib/static_model/base.rb
CHANGED
@@ -32,6 +32,10 @@ module StaticModel
|
|
32
32
|
def attribute_names
|
33
33
|
(attributes.keys | self.class.class_attributes.keys).collect {|k| k.to_s }
|
34
34
|
end
|
35
|
+
|
36
|
+
def has_attribute?(name)
|
37
|
+
name.to_s == 'id' || attribute_names.include?(name.to_s)
|
38
|
+
end
|
35
39
|
|
36
40
|
class << self
|
37
41
|
|
@@ -70,18 +74,17 @@ module StaticModel
|
|
70
74
|
alias_method :last, :find_last
|
71
75
|
|
72
76
|
def find_all_by(attribute, value)
|
73
|
-
records.find_all {|r| r.send(attribute) == value }
|
77
|
+
records.find_all {|r| r.has_attribute?(attribute) ? (r.send(attribute) == value) : false }
|
74
78
|
end
|
75
79
|
|
76
80
|
def find_first_by(attribute, value)
|
77
|
-
records.find {|r| r.send(attribute) == value }
|
81
|
+
records.find {|r| r.has_attribute?(attribute) ? (r.send(attribute) == value) : false }
|
78
82
|
end
|
79
83
|
alias_method :find_by, :find_first_by
|
80
84
|
|
81
85
|
def find_last_by(attribute, value)
|
82
|
-
records.find {|r| r.send(attribute) == value }
|
86
|
+
records.reverse.find {|r| r.has_attribute?(attribute) ? (r.send(attribute) == value) : false }
|
83
87
|
end
|
84
|
-
alias_method :find_by, :find_last_by
|
85
88
|
|
86
89
|
def load(reload = false)
|
87
90
|
return if loaded? && !reload
|
@@ -186,7 +189,7 @@ module StaticModel
|
|
186
189
|
private
|
187
190
|
def method_missing(meth, *args)
|
188
191
|
attribute_name = meth.to_s.gsub(/=$/,'')
|
189
|
-
if
|
192
|
+
if has_attribute?(attribute_name)
|
190
193
|
if meth.to_s =~ /=$/
|
191
194
|
# set
|
192
195
|
return set_attribute(attribute_name, args[0])
|
data/lib/static_model.rb
CHANGED
data/static_model.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{static_model}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.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"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-14}
|
13
13
|
s.description = %q{StaticModel provides a Base class much like ActiveRecord which supports reading from a YAML file and basic associations to ActiveRecord}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.rdoc"
|
data/test/data/books.yml
CHANGED
data/test/test_static_model.rb
CHANGED
@@ -40,6 +40,17 @@ class TestStaticModel < Test::Unit::TestCase
|
|
40
40
|
assert_equal @book.inspect, @book.to_s
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
context "has_attribute?" do
|
45
|
+
should "return false if attribute doesn't exist" do
|
46
|
+
assert !@book.has_attribute?(:blurgh)
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return true if attribute exists" do
|
50
|
+
assert @book.has_attribute?(:id)
|
51
|
+
assert @book.has_attribute?(:title)
|
52
|
+
end
|
53
|
+
end
|
43
54
|
|
44
55
|
context "comparing" do
|
45
56
|
|
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: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Quint
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|