power_enum 1.3.4 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmI3NzljN2JiODEzOTQyOWMxMDk0N2ZjYjQ5ZGUwOTIwMmMyNWRkZA==
5
+ data.tar.gz: !binary |-
6
+ NjAzMjkzYzg0YTJjNmEyYjIyYTExNjJkMWU3NmRlYjg3ZWFiZjgxNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MjI5NDI4NWU2NDJiNTY5ZjY5NTc5YmU4NWQ5ODRmMDY5OWY3NTU0ZTZkMWVi
10
+ YTA3ODBjMmNmOTBkMzEzZGJiM2MzOTY2YmE5MTA4MjI2NmEyODk5MWFhYTky
11
+ MTkwY2RlZmRmYTZjODJkOWI1MDQ2NDkxYmFmOTY0ZmU4ZWNkOTU=
12
+ data.tar.gz: !binary |-
13
+ ZWUwOTY5NTM5NjVkZjNjMjhmMjAwYzkyMTllMTcwZDFjY2Q0YmYxNDkwMjY1
14
+ NGZmYzRiZjMyMjdiMDY3OTRmYjA0NzVjMThiY2YzNDgzNzE1NWE5YzVlMjU0
15
+ MDgxN2Y3OGJmODAxMDFhZGMyOTBlNGIwMDFlN2FhYWMyNjY1NzU=
checksums.yaml.gz.sig ADDED
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::Base
5
+ class EnumGenerator < Rails::Generators::NamedBase
6
6
  require File.expand_path('../enum_generator_helpers/migration_number', __FILE__)
7
- include EnumGeneratorHelpers::MigrationNumber
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
- template migration_template, "db/migrate/#{migration_file_name}.rb" if options.migration?
21
+ migration_template 'rails31_migration.rb.erb', "db/migrate/create_enum_#{table_name}.rb" if options.migration?
22
22
  end
23
23
 
24
- hook_for :test_framework, :as => :model do |enum_generator_instance, test_generator_class|
25
- # Need to do this because I'm changing the default value of the 'fixture' option.
26
- enum_generator_instance.invoke( test_generator_class, [enum_generator_instance.enum_name], { 'fixture' => enum_generator_instance.options.fixture? } )
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
@@ -1,3 +1,3 @@
1
- class <%= enum_class_name %> < ActiveRecord::Base
1
+ class <%= class_name %> < ActiveRecord::Base
2
2
  acts_as_enumerated
3
3
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
5
- prerelease:
4
+ version: 1.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Trevor Squires
@@ -40,12 +39,11 @@ cert_chain:
40
39
  amZaYUtWM2wwYTFkR2wyUVNMa2pScFFaRDFiRCtVSDdnT3F5N1piZGNzUkJM
41
40
  NEg3VTV6VQpibEtkZEg2dXhDckRTTTdLYWJrelNPVmYKLS0tLS1FTkQgQ0VS
42
41
  VElGSUNBVEUtLS0tLQo=
43
- date: 2013-08-20 00:00:00.000000000 Z
42
+ date: 2014-01-21 00:00:00.000000000 Z
44
43
  dependencies:
45
44
  - !ruby/object:Gem::Dependency
46
45
  name: rails
47
46
  requirement: !ruby/object:Gem::Requirement
48
- none: false
49
47
  requirements:
50
48
  - - ~>
51
49
  - !ruby/object:Gem::Version
@@ -53,7 +51,6 @@ dependencies:
53
51
  type: :runtime
54
52
  prerelease: false
55
53
  version_requirements: !ruby/object:Gem::Requirement
56
- none: false
57
54
  requirements:
58
55
  - - ~>
59
56
  - !ruby/object:Gem::Version
@@ -61,7 +58,6 @@ dependencies:
61
58
  - !ruby/object:Gem::Dependency
62
59
  name: jeweler
63
60
  requirement: !ruby/object:Gem::Requirement
64
- none: false
65
61
  requirements:
66
62
  - - ! '>='
67
63
  - !ruby/object:Gem::Version
@@ -69,7 +65,6 @@ dependencies:
69
65
  type: :development
70
66
  prerelease: false
71
67
  version_requirements: !ruby/object:Gem::Requirement
72
- none: false
73
68
  requirements:
74
69
  - - ! '>='
75
70
  - !ruby/object:Gem::Version
@@ -77,7 +72,6 @@ dependencies:
77
72
  - !ruby/object:Gem::Dependency
78
73
  name: yard
79
74
  requirement: !ruby/object:Gem::Requirement
80
- none: false
81
75
  requirements:
82
76
  - - ! '>='
83
77
  - !ruby/object:Gem::Version
@@ -85,7 +79,6 @@ dependencies:
85
79
  type: :development
86
80
  prerelease: false
87
81
  version_requirements: !ruby/object:Gem::Requirement
88
- none: false
89
82
  requirements:
90
83
  - - ! '>='
91
84
  - !ruby/object:Gem::Version
@@ -93,7 +86,6 @@ dependencies:
93
86
  - !ruby/object:Gem::Dependency
94
87
  name: rspec
95
88
  requirement: !ruby/object:Gem::Requirement
96
- none: false
97
89
  requirements:
98
90
  - - ! '>='
99
91
  - !ruby/object:Gem::Version
@@ -101,7 +93,6 @@ dependencies:
101
93
  type: :development
102
94
  prerelease: false
103
95
  version_requirements: !ruby/object:Gem::Requirement
104
- none: false
105
96
  requirements:
106
97
  - - ! '>='
107
98
  - !ruby/object:Gem::Version
@@ -109,7 +100,6 @@ dependencies:
109
100
  - !ruby/object:Gem::Dependency
110
101
  name: sqlite3
111
102
  requirement: !ruby/object:Gem::Requirement
112
- none: false
113
103
  requirements:
114
104
  - - ! '>='
115
105
  - !ruby/object:Gem::Version
@@ -117,7 +107,6 @@ dependencies:
117
107
  type: :development
118
108
  prerelease: false
119
109
  version_requirements: !ruby/object:Gem::Requirement
120
- none: false
121
110
  requirements:
122
111
  - - ! '>='
123
112
  - !ruby/object:Gem::Version
@@ -125,7 +114,6 @@ dependencies:
125
114
  - !ruby/object:Gem::Dependency
126
115
  name: genspec
127
116
  requirement: !ruby/object:Gem::Requirement
128
- none: false
129
117
  requirements:
130
118
  - - ! '>='
131
119
  - !ruby/object:Gem::Version
@@ -133,7 +121,6 @@ dependencies:
133
121
  type: :development
134
122
  prerelease: false
135
123
  version_requirements: !ruby/object:Gem::Requirement
136
- none: false
137
124
  requirements:
138
125
  - - ! '>='
139
126
  - !ruby/object:Gem::Version
@@ -178,28 +165,26 @@ files:
178
165
  homepage: http://github.com/albertosaurus/power_enum
179
166
  licenses:
180
167
  - MIT
168
+ metadata: {}
181
169
  post_install_message:
182
170
  rdoc_options: []
183
171
  require_paths:
184
172
  - lib
185
173
  required_ruby_version: !ruby/object:Gem::Requirement
186
- none: false
187
174
  requirements:
188
175
  - - ! '>='
189
176
  - !ruby/object:Gem::Version
190
177
  version: '0'
191
178
  required_rubygems_version: !ruby/object:Gem::Requirement
192
- none: false
193
179
  requirements:
194
180
  - - ! '>='
195
181
  - !ruby/object:Gem::Version
196
182
  version: '0'
197
183
  requirements: []
198
184
  rubyforge_project:
199
- rubygems_version: 1.8.25
185
+ rubygems_version: 2.0.3
200
186
  signing_key:
201
- specification_version: 3
187
+ specification_version: 4
202
188
  summary: Allows you to treat instances of your ActiveRecord models as though they
203
189
  were an enumeration of values
204
190
  test_files: []
205
- has_rdoc:
metadata.gz.sig CHANGED
Binary file