static_model 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.4 2009-12-14
2
+
3
+ * Finds don't care if attribute doesn't exist on certain records
4
+ * Base#has_attribute?
5
+
1
6
  == 0.2.3 2009-12-03
2
7
 
3
8
  * Fixed active_support dependency
@@ -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 attribute_names.include?(attribute_name)
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
@@ -7,7 +7,7 @@ require 'erb' unless defined?(ERB)
7
7
  require 'active_support'
8
8
 
9
9
  module StaticModel
10
- VERSION = '0.2.3'
10
+ VERSION = '0.2.4'
11
11
  end
12
12
 
13
13
  require 'static_model/errors'
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.3"
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-03}
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
@@ -18,5 +18,4 @@
18
18
  title: Choke
19
19
  author: Chuck Palahniuk
20
20
  author_id: 3
21
- genre: Humor
22
21
 
@@ -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.3
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-03 00:00:00 -05:00
12
+ date: 2009-12-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency