paraseba-enum_field 0.1.0 → 0.1.1

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.
@@ -12,6 +12,6 @@ Module.send(:include, EnumField::DefineEnum)
12
12
  ActiveRecord::Base.send(:extend, EnumField::EnumeratedAttribute)
13
13
 
14
14
  module EnumField
15
- VERSION = '0.1.0'
15
+ VERSION = '0.1.1'
16
16
 
17
17
  end
@@ -4,6 +4,7 @@ module EnumField
4
4
  @target = target
5
5
  @next_id = 0
6
6
  @id2obj = {}
7
+ @name2obj = {}
7
8
  @sorted = []
8
9
  end
9
10
 
@@ -11,13 +12,17 @@ module EnumField
11
12
  obj, candidate_id = process_options(options)
12
13
  assign_id(obj, candidate_id)
13
14
  define_in_meta(name) { obj }
14
- save(obj)
15
+ save(name, obj)
15
16
  end
16
17
 
17
18
  def all
18
19
  @sorted.dup
19
20
  end
20
21
 
22
+ def names
23
+ @name2obj.keys
24
+ end
25
+
21
26
  def find(id)
22
27
  find_by_id(id) or raise EnumField::ObjectNotFound
23
28
  end
@@ -62,9 +67,10 @@ module EnumField
62
67
  [options[:object] || @target.new, options[:id]]
63
68
  end
64
69
 
65
- def save(obj)
70
+ def save(name, obj)
66
71
  @id2obj[obj.id] = obj
67
72
  @sorted << obj
73
+ @name2obj[name] = obj
68
74
  end
69
75
 
70
76
  end
@@ -4,7 +4,7 @@ module EnumField
4
4
  @enum_builder ||= EnumField::Builder.new(self)
5
5
  yield @enum_builder
6
6
 
7
- [:all, :find_by_id, :find, :first, :last].each do |method|
7
+ [:all, :names, :find_by_id, :find, :first, :last].each do |method|
8
8
  instance_eval <<-END
9
9
  def #{method}(*args, &block)
10
10
  @enum_builder.send(:#{method}, *args, &block)
@@ -153,6 +153,15 @@ describe EnumField::DefineEnum do
153
153
  Positions.all.should == [Positions.top, Positions.right, Positions.bottom, Positions.left]
154
154
  end
155
155
 
156
+ it "should define names method" do
157
+ Positions.should respond_to(:names)
158
+ end
159
+
160
+ it "should return all names method" do
161
+ Positions.names.should include(:top, :right, :bottom, :left)
162
+ Positions.names.size.should == 4
163
+ end
164
+
156
165
  it "should provide find_by_id and find working for autogenerated ids" do
157
166
  Positions.find_by_id(1).should == Positions.top
158
167
  Positions.find(1).should == Positions.top
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paraseba-enum_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Sebasti\xC3\xA1n Bernardo Galkin"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-15 00:00:00 -07:00
12
+ date: 2009-06-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency