enumerated_attribute 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -20,14 +20,16 @@ Install
20
20
 
21
21
  == Notice
22
22
 
23
- Not yet Rails3 compliant -- but getting close. Stay tuned.
23
+ * Rails 3 ... dynamic finders working... should be rails3 ready. We are completing form tests.
24
24
 
25
- Be a good coder ... get state pattern support for your enumerated attributes (enumerated_state[http://github.com/jeffp/enumerated_state])
25
+ * Rails 2.3.8 breaks find_or_create_by_... and find_or_initialize_by_... methods. Write me if you gotta have it... otherwise happy Rails3.
26
+
27
+ * Write cleaner code ... implement state patterns for your enumerated attributes (enumerated_state[http://github.com/jeffp/enumerated_state])
26
28
 
27
29
  == How to submit an Issue
28
30
 
29
31
  If something needs fixed, please submit issues to this Github project in the Issues tab and
30
- provide a series of FAILING RSPEC files that I can drop into the current RSpec
32
+ provide a series of FAILING RSPEC tests that I can drop into the current RSpec
31
33
  test framework and run with little to no coersing. Thanks.
32
34
 
33
35
  == Contributors
@@ -47,7 +49,7 @@ along with the following features:
47
49
  * Scaffold generator integration
48
50
  * Definable enumeration labels
49
51
  * Enum helper methods
50
- * Syntactical predicate methods
52
+ * Dynamic predicate methods
51
53
  * Initialization
52
54
  * State pattern support (enumerated_state[http://github.com/jeffp/enumerated_state])
53
55
 
@@ -70,9 +70,9 @@ module EnumeratedAttribute
70
70
  private
71
71
 
72
72
  def construct_attributes_from_arguments(attribute_names, arguments)
73
- attributes = super
74
- attributes.each { |k,v| attributes[k] = v.to_s if has_enumerated_attribute?(k) }
75
- attributes
73
+ attributes = {}
74
+ attribute_names.each_with_index{|name, idx| attributes[name] = has_enumerated_attribute?(name) ? arguments[idx].to_s : arguments[idx]}
75
+ attributes
76
76
  end
77
77
 
78
78
  def instantiate(record)
@@ -99,10 +99,15 @@ module EnumeratedAttribute
99
99
  result
100
100
  end
101
101
  end
102
+ unless private_method_defined?(:method_missing_without_enumerated_attribute)
103
+ define_chained_method(:method_missing, :enumerated_attribute) do |method_id, *arguments|
104
+ arguments = arguments.map{|arg| arg.is_a?(Symbol) ? arg.to_s : arg }
105
+ method_missing_without_enumerated_attribute(method_id, *arguments)
106
+ end
107
+ end
102
108
  end
103
109
  end
104
110
  end
105
-
106
111
  end
107
112
  end
108
113
  end
@@ -65,8 +65,29 @@ describe "RaceCar" do
65
65
  s.gear_is_nil?.should be_false
66
66
  s.gear_is_not_nil?.should be_true
67
67
  end
68
-
69
- it "should find record by enumerated column :gear attributes" do
68
+
69
+ it "should be created and found with dynamic find or creator method" do
70
+ s = RaceCar.find_or_create_by_name_and_gear('specialty', :second)
71
+ s.should_not be_nil
72
+ s.gear.should == :second
73
+ s.name.should == 'specialty'
74
+
75
+ s0 = RaceCar.find_or_create_by_name_and_gear('specialty', :second)
76
+ s0.gear.should == :second
77
+ s0.id.should == s.id
78
+ end
79
+ it "should be initialized with dynamic find or initialize method" do
80
+ s = RaceCar.find_or_initialize_by_name_and_gear('myspecialty', :second)
81
+ s.should_not be_nil
82
+ s.gear.should == :second
83
+ s.name.should == 'myspecialty'
84
+ lambda { s.save! }.should_not raise_exception
85
+
86
+ s0 = RaceCar.find_or_initialize_by_name_and_gear('myspecialty', :second)
87
+ s0.gear.should == :second
88
+ s0.id.should == s.id
89
+ end
90
+ it "should find record using dynamic finder by enumerated column :gear attributes" do
70
91
  r=RaceCar.new
71
92
  r.gear = :second
72
93
  r.name = 'special'
@@ -0,0 +1,12 @@
1
+ require 'cfg'
2
+
3
+ r=RaceCar.new
4
+ r.gear = :second
5
+ r.name = 'special'
6
+ r.save!
7
+
8
+ #RaceCar.find_by_gear_and_name(:second, 'special')
9
+ car = RaceCar.find_or_create_by_name_and_gear('special', :second)
10
+ debugger
11
+ car0 = RaceCar.find_or_create_by_name_and_gear('special', :second)
12
+ car0
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerated_attribute
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 12
10
- version: 0.2.12
8
+ - 13
9
+ version: 0.2.13
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jeff Patmon
@@ -15,18 +14,16 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-05-29 00:00:00 -07:00
17
+ date: 2010-05-30 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: meta_programming
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 21
30
27
  segments:
31
28
  - 0
32
29
  - 2
@@ -62,6 +59,7 @@ files:
62
59
  - spec/active_record/associations_spec.rb
63
60
  - spec/active_record/sti_classes.rb
64
61
  - spec/active_record/active_record_spec.rb
62
+ - spec/active_record/df.rb
65
63
  - spec/active_record/single_table_inheritance_spec.rb
66
64
  - spec/active_record/association_test_classes.rb
67
65
  - spec/active_record/inheritance_classes.rb
@@ -158,27 +156,23 @@ rdoc_options: []
158
156
  require_paths:
159
157
  - lib
160
158
  required_ruby_version: !ruby/object:Gem::Requirement
161
- none: false
162
159
  requirements:
163
160
  - - ">="
164
161
  - !ruby/object:Gem::Version
165
- hash: 3
166
162
  segments:
167
163
  - 0
168
164
  version: "0"
169
165
  required_rubygems_version: !ruby/object:Gem::Requirement
170
- none: false
171
166
  requirements:
172
167
  - - ">="
173
168
  - !ruby/object:Gem::Version
174
- hash: 3
175
169
  segments:
176
170
  - 0
177
171
  version: "0"
178
172
  requirements: []
179
173
 
180
174
  rubyforge_project:
181
- rubygems_version: 1.3.7
175
+ rubygems_version: 1.3.6
182
176
  signing_key:
183
177
  specification_version: 3
184
178
  summary: Add enumerated attributes to your models and expose them in drop-down lists in your views