power_enum 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/generators/enum/enum_generator.rb +11 -39
- data/lib/generators/enum/enum_generator_helpers/migration_number.rb +3 -13
- data/lib/generators/enum/templates/model.rb.erb +1 -1
- metadata +4 -5
- metadata.gz.sig +1 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGUyY2Y2OGNiNzZmNWEwNjZiNmY2NzcyNjI4NzQxMTQ4ZDcwYTJkNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmMzZDk2ODM3OWY5OTZlMzY4ZmY4ZmI0MjQ4ZGMyMDc5NzEzNjdjNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzY3NTQ4MWUzMjJmNmI4MjU1OTM3NDQxNGM0ODE3MzAzYTRmMDIyZmZjM2Ji
|
10
|
+
ZTdiMWY2M2U1OThkMTJlM2QzYTU5YWFjOWFiM2QxODE1ODc1OWMwYzdkMjk4
|
11
|
+
ZTFmODZhNTI2NzBhMTJlM2RjMTQ2ZWJjNTY5NjU0OWI0OWUxN2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWY2NDRlYWNmZWEzMDFiZWUzMWIxNzg2YjAzOTU0M2QyZTYxYmZlMGZmZTY1
|
14
|
+
ZDk5NDc5NDc0NzQyZGRlMWRhYmI1OTg2NjRkYTFkZGU2NTYzN2M0NzM3NTEy
|
15
|
+
ZDU5ZmE4ZDM5YTg1MWNiMjQ2ZWY0N2Q5NzM0N2Q4ODgyOTc1NWQ=
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -2,12 +2,12 @@
|
|
2
2
|
# Released under the MIT license. See LICENSE for details.
|
3
3
|
|
4
4
|
# Generator for PowerEnum
|
5
|
-
class EnumGenerator < Rails::Generators::
|
5
|
+
class EnumGenerator < Rails::Generators::NamedBase
|
6
6
|
require File.expand_path('../enum_generator_helpers/migration_number', __FILE__)
|
7
|
-
include
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
extend EnumGeneratorHelpers::MigrationNumber
|
8
9
|
|
9
10
|
source_root File.expand_path('../templates', __FILE__)
|
10
|
-
argument :enum_name, :type => :string
|
11
11
|
class_option :migration, :type => :boolean, :default => true, :desc => 'Generate migration for the enum'
|
12
12
|
class_option :fixture, :type => :boolean, :default => false, :desc => 'Generate fixture for the enum'
|
13
13
|
|
@@ -18,45 +18,17 @@ class EnumGenerator < Rails::Generators::Base
|
|
18
18
|
|
19
19
|
# Generates the migration to create the enum table.
|
20
20
|
def generate_migration
|
21
|
-
|
21
|
+
migration_template 'rails31_migration.rb.erb', "db/migrate/create_enum_#{table_name}.rb" if options.migration?
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# Do not pluralize enumeration names
|
25
|
+
def pluralize_table_names?
|
26
|
+
false
|
27
27
|
end
|
28
|
-
|
29
|
-
no_tasks do
|
30
|
-
|
31
|
-
# Returns the file name of the enum model without the .rb extension.
|
32
|
-
def file_name
|
33
|
-
enum_name.underscore
|
34
|
-
end
|
35
|
-
|
36
|
-
# Returns the class name of the enum.
|
37
|
-
def enum_class_name
|
38
|
-
file_name.camelize
|
39
|
-
end
|
40
|
-
|
41
|
-
# Derives the name for the migration, something like 'create_enum_fruit'
|
42
|
-
def migration_name
|
43
|
-
"create_enum_#{file_name}"
|
44
|
-
end
|
45
|
-
|
46
|
-
# Returns the class name of our migration
|
47
|
-
def migration_class_name
|
48
|
-
migration_name.camelize
|
49
|
-
end
|
50
|
-
|
51
|
-
# Generates and returns the filename of our migration
|
52
|
-
def migration_file_name
|
53
|
-
"#{next_migration_number}_#{migration_name}"
|
54
|
-
end
|
55
|
-
|
56
|
-
# Returns the name of the template file for the migration.
|
57
|
-
def migration_template
|
58
|
-
'rails31_migration.rb.erb'
|
59
|
-
end
|
60
28
|
|
29
|
+
hook_for :test_framework, :as => :model do |enum_generator_instance, test_generator_class|
|
30
|
+
# Need to do this because I'm changing the default value of the 'fixture' option.
|
31
|
+
table_name = enum_generator_instance.send(:table_name)
|
32
|
+
enum_generator_instance.invoke( test_generator_class, [table_name], { 'fixture' => enum_generator_instance.options.fixture? } )
|
61
33
|
end
|
62
34
|
end
|
@@ -2,23 +2,13 @@
|
|
2
2
|
module EnumGeneratorHelpers
|
3
3
|
# Helper methods to figure out the migration number.
|
4
4
|
module MigrationNumber
|
5
|
-
|
6
|
-
# Returns the number of the last migration.
|
7
|
-
# @return [Fixnum]
|
8
|
-
def current_migration_number
|
9
|
-
dirname = "#{Rails.root}/db/migrate/[0-9]*_*.rb"
|
10
|
-
Dir.glob(dirname).collect do |file|
|
11
|
-
File.basename(file).split("_").first.to_i
|
12
|
-
end.max.to_i
|
13
|
-
end
|
14
|
-
|
15
5
|
# Returns the next upcoming migration number. Sadly, Rails has no API for
|
16
6
|
# this, so we're reduced to copying from ActiveRecord::Generators::Migration
|
17
7
|
# @return [Fixnum]
|
18
|
-
def next_migration_number
|
8
|
+
def next_migration_number(dirname)
|
19
9
|
# Lifted directly from ActiveRecord::Generators::Migration
|
20
10
|
# Unfortunately, no API is provided by Rails at this time.
|
21
|
-
next_migration_number = current_migration_number + 1
|
11
|
+
next_migration_number = current_migration_number(dirname) + 1
|
22
12
|
if ActiveRecord::Base.timestamped_migrations
|
23
13
|
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
24
14
|
else
|
@@ -27,4 +17,4 @@ module EnumGeneratorHelpers
|
|
27
17
|
end
|
28
18
|
|
29
19
|
end
|
30
|
-
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Squires
|
@@ -39,7 +39,7 @@ cert_chain:
|
|
39
39
|
amZaYUtWM2wwYTFkR2wyUVNMa2pScFFaRDFiRCtVSDdnT3F5N1piZGNzUkJM
|
40
40
|
NEg3VTV6VQpibEtkZEg2dXhDckRTTTdLYWJrelNPVmYKLS0tLS1FTkQgQ0VS
|
41
41
|
VElGSUNBVEUtLS0tLQo=
|
42
|
-
date:
|
42
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
43
43
|
dependencies:
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: rails
|
@@ -117,14 +117,14 @@ dependencies:
|
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version: 0.2.
|
120
|
+
version: 0.2.8
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
123
|
version_requirements: !ruby/object:Gem::Requirement
|
124
124
|
requirements:
|
125
125
|
- - ! '>='
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version: 0.2.
|
127
|
+
version: 0.2.8
|
128
128
|
description: ! 'Power Enum allows you to treat instances of your ActiveRecord models
|
129
129
|
as though they were an enumeration of values.
|
130
130
|
|
@@ -188,4 +188,3 @@ specification_version: 4
|
|
188
188
|
summary: Allows you to treat instances of your ActiveRecord models as though they
|
189
189
|
were an enumeration of values
|
190
190
|
test_files: []
|
191
|
-
has_rdoc:
|
metadata.gz.sig
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
|
2
|
-
�9�¡�����$ѥ�)����X�|̺�S�<�J�ռ��
|
3
|
-
��6�{��`�*�fq�LYB]�8@ܮ7���
|
1
|
+
��Ȗ�R����3�t@j]�@W/Eh�x3�<���&H!�x�V_Ξh`�(`n\M���b�|�z~��G���Q<���g� J*�S���~�%B�);$i���T��S��pi�Dޞ��%$�h��<������υ��Q[���x��?�]��L���e����>�kuˏ<}@�9����
|