enumerate_it 1.0.0 → 1.0.1

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 (1.0.0)
4
+ enumerate_it (1.0.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -39,10 +39,6 @@ What does it mean when we say that someone or something is '2'?
39
39
 
40
40
  Enter EnumerateIt.
41
41
 
42
- == Documentation
43
-
44
- http://rubydoc.info/gems/enumerate_it/1.0.0/frames
45
-
46
42
  == About versions compatibility
47
43
 
48
44
  Versions 1.x.x are NOT backwards compatible with 0.x.x versions. The biggest difference is that on 1.0.0 you need to `extend` the EnumerateIt
@@ -268,11 +264,13 @@ You can also translate specific values:
268
264
 
269
265
  == Using with Rails
270
266
 
271
- * Create an initializer with the following code:
267
+ * Add the gem to your Gemfile:
272
268
 
273
- ActiveRecord::Base.extend EnumerateIt
269
+ gem "enumerate_it"
274
270
 
275
- * Add the 'enumerate_it' gem as a dependency in your environment.rb (Rails 2.3.x) or Gemfile (if you're using Bundler)
271
+ * Run the install generator:
272
+
273
+ rails g enumerate_it:install
276
274
 
277
275
  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:
278
276
 
@@ -286,23 +284,6 @@ There is also a Rails Generator that you can use to generate enumerations and th
286
284
 
287
285
  rails generate enumerate_it --help
288
286
 
289
- == Ruby 1.9
290
-
291
- EnumerateIt is fully compatible with Ruby 1.9.1 and 1.9.2 (all tests pass)
292
-
293
- * Note: on ruby 1.9.2, if you are using the enumerations in a separate folder like app/models/enumerations, and have to use the :with parameter, you have to clear the enum class namespace to a global scope by using ::EnumClass instead of EnumClass:
294
-
295
- # 1.8.7
296
- class Person < ActiveRecord::Base
297
- has_enumeration_for :relationship_status, :with => EnumClass
298
- end
299
-
300
- # 1.9.2
301
- class Person < ActiveRecord::Base
302
- has_enumeration_for :relationship_status, :with => ::EnumClass
303
- end
304
-
305
-
306
287
  == Why did you reinvent the wheel?
307
288
 
308
289
  There are other similar solutions to the problem out there, but I could not find one that
@@ -1,3 +1,3 @@
1
1
  module EnumerateIt
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -2,7 +2,7 @@ Description:
2
2
  Creates an EnumerateIt class an its locale file
3
3
 
4
4
  Example:
5
- rails g enumerate_it CivilStatus single married divorced widower concubinage separated stable
5
+ rails g enumerate_it:enum CivilStatus single married divorced widower concubinage separated stable
6
6
 
7
7
  This will create:
8
8
  app/enumerations/civil_status.rb with `associate_values :single, :married, :divorced, :widower, :concubinage, :separated, :stable`
@@ -0,0 +1,47 @@
1
+ module EnumerateIt
2
+ module Generators
3
+ class EnumGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ argument :attributes, :type => 'array', :default => []
7
+
8
+ class_option :singular, :type => 'string', :desc => 'Singular name for i18n'
9
+
10
+ class_option :lang, :type => 'string', :desc => 'Lang to use in i18n', :default => 'en'
11
+
12
+ desc "Creates a locale file on config/locales"
13
+ def create_locale
14
+ template "locale.yml", File.join('config/locales', "#{singular_name}.yml")
15
+ end
16
+
17
+ desc "Creates an initializer file on config/initializers that extends ActiveRecord::Base with Enumerate_it"
18
+ def create_enumerate_it
19
+ template "enumerate_it.rb", File.join('app/enumerations', "#{singular_name}.rb")
20
+ end
21
+
22
+ protected
23
+
24
+ def default_lang
25
+ options[:lang]
26
+ end
27
+
28
+ def singular
29
+ singular_name
30
+ end
31
+
32
+ def locale_fields
33
+ attributes.map(&:name)
34
+ end
35
+
36
+ def fields
37
+ if attributes.first.type == :string
38
+ attributes.map(&:name)
39
+ else
40
+ attributes.map do |attribute|
41
+ [attribute.name, attribute.type]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Creates an initializer file for EnumerateIt
3
+
4
+ Example:
5
+ rails generate enumerate_it:install
6
+
7
+ This will create:
8
+ config/initializers/enumerate_it.rb
@@ -0,0 +1,11 @@
1
+ module EnumerateIt
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def copy_initializer_file
7
+ template "enumerate_it_initializer.rb", File.join('config/initializers/', "enumerate_it.rb")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ ActiveRecord::Base.extend EnumerateIt
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: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-08 00:00:00.000000000 Z
12
+ date: 2012-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -98,10 +98,13 @@ files:
98
98
  - lib/enumerate_it/base.rb
99
99
  - lib/enumerate_it/class_methods.rb
100
100
  - lib/enumerate_it/version.rb
101
- - lib/generators/USAGE
102
- - lib/generators/enumerate_it_generator.rb
103
- - lib/generators/templates/enumerate_it.rb
104
- - lib/generators/templates/locale.yml
101
+ - lib/generators/enumerate_it/enum/USAGE
102
+ - lib/generators/enumerate_it/enum/enum_generator.rb
103
+ - lib/generators/enumerate_it/enum/templates/enumerate_it.rb
104
+ - lib/generators/enumerate_it/enum/templates/locale.yml
105
+ - lib/generators/enumerate_it/install/USAGE
106
+ - lib/generators/enumerate_it/install/install_generator.rb
107
+ - lib/generators/enumerate_it/install/templates/enumerate_it_initializer.rb
105
108
  - spec/enumerate_it_spec.rb
106
109
  - spec/i18n/en.yml
107
110
  - spec/i18n/pt.yml
@@ -121,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
124
  version: '0'
122
125
  segments:
123
126
  - 0
124
- hash: -1315505449336147275
127
+ hash: 4432600982721649974
125
128
  required_rubygems_version: !ruby/object:Gem::Requirement
126
129
  none: false
127
130
  requirements:
@@ -130,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
133
  version: '0'
131
134
  segments:
132
135
  - 0
133
- hash: -1315505449336147275
136
+ hash: 4432600982721649974
134
137
  requirements: []
135
138
  rubyforge_project:
136
139
  rubygems_version: 1.8.24
@@ -1,41 +0,0 @@
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