enumerate_it 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -55,7 +55,7 @@ This will create some nice stuff:
55
55
 
56
56
  * Each enumeration's value will turn into a constant:
57
57
 
58
- RelationshipsStatus::SINGLE # returns 1
58
+ RelationshipStatus::SINGLE # returns 1
59
59
  RelationshipStatus::MARRIED # returns 2 and so on...
60
60
 
61
61
  * You can retrieve a list with all the enumeration codes:
@@ -66,9 +66,9 @@ This will create some nice stuff:
66
66
 
67
67
  RelationshipStatus.to_a # [["Divorced", 4],["Married", 2],["Single", 1],["Widow", 3]]
68
68
 
69
- * You can retrive a list with values for a group of enumeration constants.
69
+ * You can retrieve a list with values for a group of enumeration constants.
70
70
 
71
- RelationshipStatus.valus_for %w(MARRIED SINGLE) # [2, 1]
71
+ RelationshipStatus.values_for %w(MARRIED SINGLE) # [2, 1]
72
72
 
73
73
  * You can manipulate the hash used to create the enumeration:
74
74
 
@@ -161,7 +161,7 @@ located on enumerations.'enumeration_name'.'key' :
161
161
  pt:
162
162
  enumerations:
163
163
  relationship_status:
164
- single: Casado
164
+ married: Casado
165
165
 
166
166
  p = Person.new
167
167
  p.relationship_status = RelationshipStatus::MARRIED
@@ -195,7 +195,7 @@ An interesting approach to use it in Rails apps is to create an app/models/enume
195
195
 
196
196
  == Ruby 1.9
197
197
 
198
- EnumerateIt is fully compatible with Ruby 1.9.1 (all tests pass)
198
+ EnumerateIt is fully compatible with Ruby 1.9.1 and 1.9.2 (all tests pass)
199
199
 
200
200
  == Why did you reinvent the wheel?
201
201
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
data/enumerate_it.gemspec CHANGED
@@ -1,44 +1,42 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{enumerate_it}
8
- s.version = "0.7.0"
8
+ s.version = "0.7.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["C\303\241ssio Marques"]
12
- s.date = %q{2010-11-08}
12
+ s.date = %q{2010-12-16}
13
13
  s.description = %q{Have a legacy database and need some enumerations in your models to match those stupid '4 rows/2 columns' tables with foreign keys and stop doing joins just to fetch a simple description? Or maybe use some integers instead of strings as the code for each value of your enumerations? Here's EnumerateIt.}
14
14
  s.email = %q{cassiommc@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "enumerate_it.gemspec",
27
- "lib/enumerate_it.rb",
28
- "spec/enumerate_it_spec.rb",
29
- "spec/i18n/en.yml",
30
- "spec/i18n/pt.yml",
31
- "spec/spec.opts",
32
- "spec/spec_helper.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "enumerate_it.gemspec",
26
+ "lib/enumerate_it.rb",
27
+ "spec/enumerate_it_spec.rb",
28
+ "spec/i18n/en.yml",
29
+ "spec/i18n/pt.yml",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
33
32
  ]
34
33
  s.homepage = %q{http://github.com/cassiomarques/enumerate_it}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
34
  s.require_paths = ["lib"]
37
35
  s.rubygems_version = %q{1.3.7}
38
36
  s.summary = %q{Ruby Enumerations}
39
37
  s.test_files = [
40
38
  "spec/enumerate_it_spec.rb",
41
- "spec/spec_helper.rb"
39
+ "spec/spec_helper.rb"
42
40
  ]
43
41
 
44
42
  if s.respond_to? :specification_version then
data/lib/enumerate_it.rb CHANGED
@@ -205,6 +205,10 @@ module EnumerateIt
205
205
  @@registered_enumerations[self].values.map {|value| [translate(value[1]), value[0]] }.sort_by { |value| value[0] }
206
206
  end
207
207
 
208
+ def self.to_range
209
+ (list.min..list.max)
210
+ end
211
+
208
212
  def self.values_for(values)
209
213
  values.map { |v| self.const_get(v.to_sym) }
210
214
  end
@@ -224,7 +228,8 @@ module EnumerateIt
224
228
  set_validations attribute, options
225
229
  create_enumeration_humanize_method options[:with], attribute
226
230
  if options[:create_helpers]
227
- create_helper_methods options[:with], attribute
231
+ create_helper_methods(options[:with], attribute)
232
+ create_mutator_methods(options[:with], attribute)
228
233
  end
229
234
  end
230
235
 
@@ -249,6 +254,16 @@ module EnumerateIt
249
254
  end
250
255
  end
251
256
 
257
+ def create_mutator_methods(klass, attribute_name)
258
+ class_eval do
259
+ klass.enumeration.each_pair do |key, values|
260
+ define_method "#{key}!" do
261
+ self.send "#{attribute_name}=", values.first
262
+ end
263
+ end
264
+ end
265
+ end
266
+
252
267
  def define_enumeration_class(attribute, options)
253
268
  if options[:with].blank?
254
269
  options[:with] = attribute.to_s.camelize.constantize
@@ -102,6 +102,18 @@ describe EnumerateIt do
102
102
  target.should be_value_2
103
103
  target.should_not be_value_1
104
104
  end
105
+
106
+ it "creates a mutator method for each enumeration value" do
107
+ [:value_1, :value_2, :value_3].each do |value|
108
+ TestClass.new(TestEnumeration::VALUE_1).should respond_to(:"#{value}!")
109
+ end
110
+ end
111
+
112
+ it "changes the attribute's value through mutator methods" do
113
+ target = TestClass.new(TestEnumeration::VALUE_2)
114
+ target.value_3!
115
+ target.foobar.should == TestEnumeration::VALUE_3
116
+ end
105
117
  end
106
118
 
107
119
  describe EnumerateIt::Base do
@@ -135,6 +147,12 @@ describe EnumerateIt do
135
147
  end
136
148
  end
137
149
 
150
+ describe "#to_range" do
151
+ it "returns a Range object containing the enumeration's value interval" do
152
+ TestEnumeration.to_range.should == ("1".."3")
153
+ end
154
+ end
155
+
138
156
  describe ".values_for" do
139
157
  it "returns an array with the corresponding values for a string array representing some of the enumeration's values" do
140
158
  TestEnumeration.values_for(%w(VALUE_1 VALUE_2)).should == [TestEnumeration::VALUE_1, TestEnumeration::VALUE_2]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerate_it
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 1
10
+ version: 0.7.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "C\xC3\xA1ssio Marques"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-08 00:00:00 -02:00
18
+ date: 2010-12-16 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,7 +45,6 @@ extra_rdoc_files:
45
45
  - README.rdoc
46
46
  files:
47
47
  - .document
48
- - .gitignore
49
48
  - LICENSE
50
49
  - README.rdoc
51
50
  - Rakefile
@@ -62,8 +61,8 @@ homepage: http://github.com/cassiomarques/enumerate_it
62
61
  licenses: []
63
62
 
64
63
  post_install_message:
65
- rdoc_options:
66
- - --charset=UTF-8
64
+ rdoc_options: []
65
+
67
66
  require_paths:
68
67
  - lib
69
68
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- enumerate_it-*.gem