enumerate_it 0.7.11 → 0.7.12

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumerate_it (0.7.10)
4
+ enumerate_it (0.7.12)
5
5
  activesupport (>= 2.3.2)
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -239,14 +239,18 @@ You can also translate specific values:
239
239
 
240
240
  * Add the 'enumerate_it' gem as a dependency in your environment.rb (Rails 2.3.x) or Gemfile (if you're using Bundler)
241
241
 
242
- An interesting approach to use it in Rails apps is to create an app/models/enumerations folder and add it to your autoload path in config/application.rb:
242
+ An interesting approach to use it in Rails apps is to create an app/enumerations folder and add it to your autoload path in config/application.rb:
243
243
 
244
244
  module YourApp
245
245
  class Application < Rails::Application
246
- config.autoload_paths << "#{Rails.root}/app/models/enumerations"
246
+ config.autoload_paths << "#{Rails.root}/app/enumerations"
247
247
  end
248
248
  end
249
249
 
250
+ There is also a Rails Generator that you can use to generate enumerations and their locale files. Take a look at how to use it running
251
+
252
+ rails generate enumerate_it --help
253
+
250
254
  == Ruby 1.9
251
255
 
252
256
  EnumerateIt is fully compatible with Ruby 1.9.1 and 1.9.2 (all tests pass)
data/lib/enumerate_it.rb CHANGED
@@ -68,7 +68,15 @@
68
68
  #
69
69
  # You can retrive 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
+ #
73
+ # You can retrieve the value for a specific enumeration constant:
74
+ #
75
+ # RelationshipStatus.value_for("MARRIED") # 2
76
+ #
77
+ # You can retrieve the symbol used to declare a specific enumeration value:
78
+ #
79
+ # RelationshipStatus.key_for(RelationshioStatus::MARRIED) # :married
72
80
  #
73
81
  # - You can manipulate the hash used to create the enumeration:
74
82
  #
@@ -1,3 +1,3 @@
1
1
  module EnumerateIt
2
- VERSION = "0.7.11"
2
+ VERSION = "0.7.12"
3
3
  end
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Creates an EnumerateIt class an its locale file
3
+
4
+ Example:
5
+ rails g enumerate_it CivilStatus single married divorced widower concubinage separated stable
6
+
7
+ This will create:
8
+ app/enumerations/civil_status.rb with `associate_values :single, :married, :divorced, :widower, :concubinage, :separated, :stable`
9
+ config/locales/civil_status.yml
10
+
11
+ rails g enumerate_it CivilStatus single:1 married:2 divorced:3 widower:4
12
+
13
+ This will create:
14
+ app/enumerations/civil_status.rb with `associate_values :single => 1, :married => 2, :divorced => 2, :widower => 4`
15
+ config/locales/civil_status.yml
@@ -0,0 +1,41 @@
1
+ class EnumerateItGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ argument :attributes, :type => 'array', :default => []
5
+
6
+ class_option :singular, :type => 'string', :desc => 'Singular name for i18n'
7
+
8
+ class_option :lang, :type => 'string', :desc => 'Lang to use in i18n', :default => 'en'
9
+
10
+ def create_locale
11
+ template "locale.yml", File.join('config/locales', "#{singular_name}.yml")
12
+ end
13
+
14
+ def create_enumerate_it
15
+ template "enumerate_it.rb", File.join('app/enumerations', "#{singular_name}.rb")
16
+ end
17
+
18
+ protected
19
+
20
+ def default_lang
21
+ options[:lang]
22
+ end
23
+
24
+ def singular
25
+ singular_name
26
+ end
27
+
28
+ def locale_fields
29
+ attributes.map(&:name)
30
+ end
31
+
32
+ def fields
33
+ if attributes.first.type == :string
34
+ attributes.map(&:name)
35
+ else
36
+ attributes.map do |attribute|
37
+ [attribute.name, attribute.type]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < EnumerateIt::Base
2
+ <% if fields.first.is_a?(Array) %>associate_values <%= fields.map {|field, value| ":#{field} => #{value}"}.join(', ') %><% else %>associate_values <%= fields.map {|field| ":#{field}"}.join(', ') %><% end %>
3
+ end
@@ -0,0 +1,6 @@
1
+ <%= default_lang %>:
2
+ enumerations:
3
+ <%= singular_name %>:
4
+ <%- locale_fields.each do |name| -%>
5
+ <%= name %>: "<%= name.capitalize %>"
6
+ <%- end -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.11
4
+ version: 0.7.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-07 00:00:00.000000000 Z
12
+ date: 2012-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2172840600 !ruby/object:Gem::Requirement
16
+ requirement: &2164309620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2172840600
24
+ version_requirements: *2164309620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2172840100 !ruby/object:Gem::Requirement
27
+ requirement: &2164309020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.5.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2172840100
35
+ version_requirements: *2164309020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activerecord
38
- requirement: &2172839640 !ruby/object:Gem::Requirement
38
+ requirement: &2164308360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 3.0.5
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2172839640
46
+ version_requirements: *2164308360
47
47
  description: Have a legacy database and need some enumerations in your models to match
48
48
  those stupid '4 rows/2 columns' tables with foreign keys and stop doing joins just
49
49
  to fetch a simple description? Or maybe use some integers instead of strings as
@@ -64,6 +64,10 @@ files:
64
64
  - enumerate_it.gemspec
65
65
  - lib/enumerate_it.rb
66
66
  - lib/enumerate_it/version.rb
67
+ - lib/generators/USAGE
68
+ - lib/generators/enumerate_it_generator.rb
69
+ - lib/generators/templates/enumerate_it.rb
70
+ - lib/generators/templates/locale.yml
67
71
  - spec/enumerate_it_spec.rb
68
72
  - spec/i18n/en.yml
69
73
  - spec/i18n/pt.yml
@@ -89,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
93
  version: '0'
90
94
  requirements: []
91
95
  rubyforge_project:
92
- rubygems_version: 1.8.10
96
+ rubygems_version: 1.8.15
93
97
  signing_key:
94
98
  specification_version: 3
95
99
  summary: Ruby Enumerations