active_enum 0.6.5 → 0.6.6

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.
@@ -124,7 +124,7 @@ You can check if the attribute value matches a particular enum value by passing
124
124
 
125
125
  A convenience method on the class is available to the enum class of any enumerated attribute
126
126
 
127
- User.enum_for(:sex) # => Sex
127
+ User.active_enum_for(:sex) # => Sex
128
128
 
129
129
  === Bulk definition
130
130
 
@@ -50,7 +50,7 @@ module ActiveEnum
50
50
  end
51
51
  end
52
52
 
53
- def enum_for(attribute)
53
+ def active_enum_for(attribute)
54
54
  self.enumerated_attributes[attribute.to_sym]
55
55
  end
56
56
 
@@ -63,13 +63,12 @@ module ActiveEnum
63
63
  #
64
64
  def define_active_enum_read_method(attribute)
65
65
  define_read_method(attribute, attribute.to_s, columns_hash[attribute.to_s]) unless instance_method_already_implemented?(attribute.to_s)
66
-
67
66
  old_method = "#{attribute}_without_enum"
68
67
  define_method("#{attribute}_with_enum") do |*arg|
69
68
  arg = arg.first
70
69
  value = send(old_method)
71
70
 
72
- enum = self.class.enum_for(attribute)
71
+ enum = self.class.active_enum_for(attribute)
73
72
  case arg
74
73
  when :id
75
74
  value if enum[value]
@@ -91,11 +90,10 @@ module ActiveEnum
91
90
  # user.sex = :male
92
91
  #
93
92
  def define_active_enum_write_method(attribute)
94
- define_write_method(attribute) unless instance_method_already_implemented?("#{attribute}=")
95
-
93
+ define_write_method(attribute) unless instance_method_already_implemented?("#{attribute}")
96
94
  old_method = "#{attribute}_without_enum="
97
95
  define_method("#{attribute}_with_enum=") do |arg|
98
- enum = self.class.enum_for(attribute)
96
+ enum = self.class.active_enum_for(attribute)
99
97
  if arg.is_a?(Symbol)
100
98
  value = enum[arg]
101
99
  send(old_method, value)
@@ -118,7 +116,7 @@ module ActiveEnum
118
116
  define_method("#{attribute}_with_enum?") do |*arg|
119
117
  arg = arg.first
120
118
  if arg
121
- send(attribute) == self.class.enum_for(attribute)[arg]
119
+ send(attribute) == self.class.active_enum_for(attribute)[arg]
122
120
  else
123
121
  send(old_method)
124
122
  end
@@ -2,7 +2,7 @@ module ActiveEnum
2
2
  module Formtastic
3
3
 
4
4
  def enum_input(method, options)
5
- raise "Attribute '#{method}' has no enum class" unless enum = @object.class.enum_for(method)
5
+ raise "Attribute '#{method}' has no enum class" unless enum = @object.class.active_enum_for(method)
6
6
  select_input(method, options.merge(:collection => enum.to_select))
7
7
  end
8
8
 
@@ -1,3 +1,3 @@
1
1
  module ActiveEnum
2
- VERSION = '0.6.5'
2
+ VERSION = '0.6.6'
3
3
  end
@@ -17,23 +17,23 @@ describe ActiveEnum::Extensions do
17
17
  ActiveRecord::Base.should respond_to(:enumerate)
18
18
  end
19
19
 
20
- it 'should add class :enum_for method to ActiveRecord' do
21
- ActiveRecord::Base.should respond_to(:enum_for)
20
+ it 'should add class :active_enum_for method to ActiveRecord' do
21
+ ActiveRecord::Base.should respond_to(:active_enum_for)
22
22
  end
23
23
 
24
24
  it 'should allow multiple attributes to be enumerated with same enum' do
25
25
  Person.class_eval do
26
26
  enumerate :attending, :staying, :with => Accepted
27
27
  end
28
- Person.enum_for(:attending).should == Accepted
29
- Person.enum_for(:staying).should == Accepted
28
+ Person.active_enum_for(:attending).should == Accepted
29
+ Person.active_enum_for(:staying).should == Accepted
30
30
  end
31
31
 
32
32
  it 'should allow implicit enumeration class from attribute name' do
33
33
  Person.class_eval do
34
34
  enumerate :sex
35
35
  end
36
- Person.enum_for(:sex).should == Sex
36
+ Person.active_enum_for(:sex).should == Sex
37
37
  end
38
38
 
39
39
  it 'should create enum namespaced enum class from block' do
@@ -42,7 +42,7 @@ describe ActiveEnum::Extensions do
42
42
  value :id => 1, :name => 'Male'
43
43
  end
44
44
  end
45
- Person.enum_for(:sex).should == Person::Sex
45
+ Person.active_enum_for(:sex).should == ::Person::Sex
46
46
  end
47
47
 
48
48
  it 'should raise error if implicit enumeration class cannot be found' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_enum
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 5
10
- version: 0.6.5
9
+ - 6
10
+ version: 0.6.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan
@@ -15,7 +15,7 @@ autorequire: active_enum
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-24 00:00:00 +10:00
18
+ date: 2010-08-06 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies: []
21
21