genesis 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/Guardfile +1 -1
- data/genesis.gemspec +1 -0
- data/lib/generators/genesis/contexts/contexts_generator.rb +30 -0
- data/lib/generators/genesis/install/install_generator.rb +30 -0
- data/lib/generators/{prepare_genesis → genesis/install}/templates/genesis.rake +0 -0
- data/lib/generators/{prepare_genesis → genesis/install}/templates/genesis_callbacks.rb +3 -1
- data/lib/generators/genesis/seed/seed_generator.rb +41 -0
- data/lib/generators/genesis/{templates → seed/templates}/migration.erb +7 -5
- data/lib/genesis/version.rb +1 -1
- data/{rails_generators/prepare_seeding/templates → lib/tasks}/genesis.rake +0 -0
- data/spec/generators/genesis/contexts/contexts_generator_spec.rb +37 -0
- data/spec/generators/genesis/install/install_generator_spec.rb +80 -0
- data/spec/generators/genesis/seed/seed_generator_spec.rb +34 -0
- data/spec/spec_helper.rb +4 -2
- metadata +30 -22
- data/.rake_tasks~ +0 -24
- data/lib/generators/genesis/genesis_generator.rb +0 -33
- data/lib/generators/genesis_contexts/genesis_contexts_generator.rb +0 -13
- data/lib/generators/prepare_genesis/prepare_genesis_generator.rb +0 -15
- data/rails_generators/genesis/USAGE +0 -0
- data/rails_generators/genesis/genesis_generator.rb +0 -50
- data/rails_generators/genesis/templates/genesis_override.rake +0 -0
- data/rails_generators/genesis/templates/migration.rb +0 -9
- data/rails_generators/genesis_contexts/USAGE +0 -0
- data/rails_generators/genesis_contexts/genesis_contexts_generator.rb +0 -44
- data/rails_generators/prepare_seeding/USAGE +0 -1
- data/rails_generators/prepare_seeding/prepare_seeding_generator.rb +0 -52
- data/rails_generators/prepare_seeding/templates/genesis_callbacks.rb +0 -13
- data/spec/generators/genesis_generator_spec.rb +0 -26
data/Guardfile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
guard 'rspec', :version => 2, :all_on_start => true, :all_after_pass => false, :cli => '--color --format doc' do
|
|
2
2
|
watch( %r{^spec/.+_spec\.rb$} )
|
|
3
|
-
watch( %r{^lib/(.+)\.rb$} ) { |m| "spec
|
|
3
|
+
watch( %r{^lib/(.+)\.rb$} ) { |m| "spec/#{m[1]}_spec.rb" }
|
|
4
4
|
watch( 'spec/spec_helper.rb' ) { "spec" }
|
|
5
5
|
end
|
data/genesis.gemspec
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
|
|
3
|
+
module Genesis
|
|
4
|
+
|
|
5
|
+
class ContextsGenerator < Rails::Generators::Base
|
|
6
|
+
|
|
7
|
+
desc "Description:\n Generate one or more context folders."
|
|
8
|
+
|
|
9
|
+
argument :contexts, :type => :string, :required => true
|
|
10
|
+
|
|
11
|
+
def self.source_root
|
|
12
|
+
File.join File.dirname(__FILE__),
|
|
13
|
+
'templates'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def install_contexts
|
|
17
|
+
normalized_contexts.each do |context|
|
|
18
|
+
empty_directory File.join( Genesis::SEEDS_ROOT, 'contexts', context )
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def normalized_contexts
|
|
23
|
+
return contexts if contexts.is_a?( Array )
|
|
24
|
+
|
|
25
|
+
contexts.split ','
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
|
|
3
|
+
module Genesis
|
|
4
|
+
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
|
|
7
|
+
desc "Description:\n Installs the genesis assets necessary to create and execute seeds."
|
|
8
|
+
|
|
9
|
+
argument :environments, :type => :string, :default => %w(development production)
|
|
10
|
+
|
|
11
|
+
def self.source_root
|
|
12
|
+
File.join File.dirname(__FILE__),
|
|
13
|
+
'templates'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def install_seeding
|
|
17
|
+
envs.each { |env| empty_directory "db/seeds/#{env}" }
|
|
18
|
+
copy_file 'genesis.rake', 'lib/tasks/genesis.rake'
|
|
19
|
+
copy_file 'genesis_callbacks.rb', 'db/seeds/genesis_callbacks.rb'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def envs
|
|
23
|
+
return environments if environments.is_a?( Array )
|
|
24
|
+
|
|
25
|
+
environments.split ','
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
|
|
3
|
+
module Genesis
|
|
4
|
+
|
|
5
|
+
class SeedGenerator < Rails::Generators::Base
|
|
6
|
+
|
|
7
|
+
desc "Description:\n Creates the specified seed file (optionally within a specificied environment)."
|
|
8
|
+
|
|
9
|
+
argument :seed_name, :type => :string, :required => true
|
|
10
|
+
argument :environment, :type => :string, :default => ''
|
|
11
|
+
|
|
12
|
+
def self.source_root
|
|
13
|
+
File.join File.dirname(__FILE__),
|
|
14
|
+
'templates'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def install_seed
|
|
18
|
+
template "migration.erb", "db/seeds/#{environment_part}#{timestamp}_#{file_name}.rb"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def file_name
|
|
24
|
+
seed_name.underscore
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def class_name
|
|
28
|
+
seed_name.camelcase
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def timestamp
|
|
32
|
+
@teimstamp ||= DateTime.now.strftime( "%Y%m%d%H%M%S" )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def environment_part
|
|
36
|
+
environment.blank? ? '' : "#{environment}/"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
data/lib/genesis/version.rb
CHANGED
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'generators/genesis/contexts/contexts_generator'
|
|
3
|
+
|
|
4
|
+
describe Genesis::ContextsGenerator do
|
|
5
|
+
|
|
6
|
+
with_args 'test1' do
|
|
7
|
+
|
|
8
|
+
it "should generate the db/seeds/test1 folder" do
|
|
9
|
+
subject.should generate( 'db/seeds/contexts/test1' )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
with_args 'test1,test2' do
|
|
15
|
+
|
|
16
|
+
%w(
|
|
17
|
+
db/seeds/contexts/test1
|
|
18
|
+
db/seeds/contexts/test2
|
|
19
|
+
).each do |folder_path|
|
|
20
|
+
|
|
21
|
+
it "should generate the #{folder_path} folder" do
|
|
22
|
+
subject.should generate( folder_path )
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
with_args '--help' do
|
|
30
|
+
|
|
31
|
+
it "should ouput the correct description in the help message" do
|
|
32
|
+
subject.should output( "Description:\n Generate one or more context folders." )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'generators/genesis/install/install_generator'
|
|
3
|
+
|
|
4
|
+
shared_examples_for 'a genesis installation generator' do
|
|
5
|
+
|
|
6
|
+
{
|
|
7
|
+
'genesis.rake', 'lib/tasks/genesis.rake',
|
|
8
|
+
'genesis_callbacks.rb', 'db/seeds/genesis_callbacks.rb'
|
|
9
|
+
}.each do |src, dest|
|
|
10
|
+
|
|
11
|
+
it "should generate the #{dest} file with the correct contents" do
|
|
12
|
+
subject.should generate( dest ) { |content|
|
|
13
|
+
content.should == File.read( File.join( source_root, src ) )
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe Genesis::InstallGenerator do
|
|
22
|
+
|
|
23
|
+
let :source_root do
|
|
24
|
+
described_class.source_root
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "with no arguments or options" do
|
|
28
|
+
|
|
29
|
+
it_should_behave_like 'a genesis installation generator'
|
|
30
|
+
|
|
31
|
+
%w(
|
|
32
|
+
db/seeds/production
|
|
33
|
+
db/seeds/development
|
|
34
|
+
).each do |folder_path|
|
|
35
|
+
|
|
36
|
+
it "should generate the #{folder_path} folder" do
|
|
37
|
+
subject.should generate( folder_path )
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
with_args 'test1' do
|
|
46
|
+
|
|
47
|
+
it_should_behave_like 'a genesis installation generator'
|
|
48
|
+
|
|
49
|
+
it "should generate the db/seeds/test1 folder" do
|
|
50
|
+
subject.should generate( 'db/seeds/test1' )
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
with_args 'test1,test2' do
|
|
56
|
+
|
|
57
|
+
it_should_behave_like 'a genesis installation generator'
|
|
58
|
+
|
|
59
|
+
%w(
|
|
60
|
+
db/seeds/test1
|
|
61
|
+
db/seeds/test2
|
|
62
|
+
).each do |folder_path|
|
|
63
|
+
|
|
64
|
+
it "should generate the #{folder_path} folder" do
|
|
65
|
+
subject.should generate( folder_path )
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
with_args '--help' do
|
|
73
|
+
|
|
74
|
+
it "should ouput the correct description in the help message" do
|
|
75
|
+
subject.should output( "Description:\n Installs the genesis assets necessary to create and execute seeds." )
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'generators/genesis/seed/seed_generator'
|
|
3
|
+
|
|
4
|
+
describe Genesis::SeedGenerator do
|
|
5
|
+
|
|
6
|
+
with_args 'create_users' do
|
|
7
|
+
|
|
8
|
+
xit "should generate the correct seed file" do
|
|
9
|
+
# subject.should generate( // )# { |content|
|
|
10
|
+
# content.should == File.read( File.join( source_root, src ) )
|
|
11
|
+
# }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
with_args 'create_users production' do
|
|
17
|
+
|
|
18
|
+
xit "should generate the correct seed file" do
|
|
19
|
+
# subject.should generate( // )# { |content|
|
|
20
|
+
# content.should == File.read( File.join( source_root, src ) )
|
|
21
|
+
# }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
with_args '--help' do
|
|
27
|
+
|
|
28
|
+
it "should ouput the correct description in the help message" do
|
|
29
|
+
subject.should output( "Description:\n Creates the specified seed file (optionally within a specificied environment)." )
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: genesis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 7
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
8
|
+
- 4
|
|
9
9
|
- 0
|
|
10
|
-
version: 1.
|
|
10
|
+
version: 1.4.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- C. Jason Harrelson
|
|
@@ -130,6 +130,20 @@ dependencies:
|
|
|
130
130
|
version: "0"
|
|
131
131
|
type: :development
|
|
132
132
|
version_requirements: *id008
|
|
133
|
+
- !ruby/object:Gem::Dependency
|
|
134
|
+
name: genspec
|
|
135
|
+
prerelease: false
|
|
136
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
|
137
|
+
none: false
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
hash: 3
|
|
142
|
+
segments:
|
|
143
|
+
- 0
|
|
144
|
+
version: "0"
|
|
145
|
+
type: :development
|
|
146
|
+
version_requirements: *id009
|
|
133
147
|
description: A data seeding solution for Ruby on Rails providing seeding facilities far more advanced than the current built in Ruby on Rails solution.
|
|
134
148
|
email:
|
|
135
149
|
- jason@lookforwardenterprises.com
|
|
@@ -142,7 +156,6 @@ extra_rdoc_files: []
|
|
|
142
156
|
files:
|
|
143
157
|
- .document
|
|
144
158
|
- .gitignore
|
|
145
|
-
- .rake_tasks~
|
|
146
159
|
- .rspec
|
|
147
160
|
- .rvmrc
|
|
148
161
|
- Gemfile
|
|
@@ -151,29 +164,22 @@ files:
|
|
|
151
164
|
- README.rdoc
|
|
152
165
|
- Rakefile
|
|
153
166
|
- genesis.gemspec
|
|
154
|
-
- lib/generators/genesis/
|
|
155
|
-
- lib/generators/genesis/
|
|
156
|
-
- lib/generators/
|
|
157
|
-
- lib/generators/
|
|
158
|
-
- lib/generators/
|
|
159
|
-
- lib/generators/
|
|
167
|
+
- lib/generators/genesis/contexts/contexts_generator.rb
|
|
168
|
+
- lib/generators/genesis/install/install_generator.rb
|
|
169
|
+
- lib/generators/genesis/install/templates/genesis.rake
|
|
170
|
+
- lib/generators/genesis/install/templates/genesis_callbacks.rb
|
|
171
|
+
- lib/generators/genesis/seed/seed_generator.rb
|
|
172
|
+
- lib/generators/genesis/seed/templates/migration.erb
|
|
160
173
|
- lib/genesis.rb
|
|
161
174
|
- lib/genesis/active_record_extensions.rb
|
|
162
175
|
- lib/genesis/create_schema_seeds.rb
|
|
163
176
|
- lib/genesis/schema_seed.rb
|
|
164
177
|
- lib/genesis/seeder.rb
|
|
165
178
|
- lib/genesis/version.rb
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
-
|
|
170
|
-
- rails_generators/genesis_contexts/USAGE
|
|
171
|
-
- rails_generators/genesis_contexts/genesis_contexts_generator.rb
|
|
172
|
-
- rails_generators/prepare_seeding/USAGE
|
|
173
|
-
- rails_generators/prepare_seeding/prepare_seeding_generator.rb
|
|
174
|
-
- rails_generators/prepare_seeding/templates/genesis.rake
|
|
175
|
-
- rails_generators/prepare_seeding/templates/genesis_callbacks.rb
|
|
176
|
-
- spec/generators/genesis_generator_spec.rb
|
|
179
|
+
- lib/tasks/genesis.rake
|
|
180
|
+
- spec/generators/genesis/contexts/contexts_generator_spec.rb
|
|
181
|
+
- spec/generators/genesis/install/install_generator_spec.rb
|
|
182
|
+
- spec/generators/genesis/seed/seed_generator_spec.rb
|
|
177
183
|
- spec/genesis_spec.rb
|
|
178
184
|
- spec/spec_helper.rb
|
|
179
185
|
has_rdoc: true
|
|
@@ -211,6 +217,8 @@ signing_key:
|
|
|
211
217
|
specification_version: 3
|
|
212
218
|
summary: A data seeding solution for Ruby on Rails.
|
|
213
219
|
test_files:
|
|
214
|
-
- spec/generators/
|
|
220
|
+
- spec/generators/genesis/contexts/contexts_generator_spec.rb
|
|
221
|
+
- spec/generators/genesis/install/install_generator_spec.rb
|
|
222
|
+
- spec/generators/genesis/seed/seed_generator_spec.rb
|
|
215
223
|
- spec/genesis_spec.rb
|
|
216
224
|
- spec/spec_helper.rb
|
data/.rake_tasks~
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
build
|
|
2
|
-
check_dependencies
|
|
3
|
-
check_dependencies:development
|
|
4
|
-
check_dependencies:runtime
|
|
5
|
-
clobber_rcov
|
|
6
|
-
clobber_rdoc
|
|
7
|
-
gemcutter:release
|
|
8
|
-
gemspec
|
|
9
|
-
gemspec:debug
|
|
10
|
-
gemspec:generate
|
|
11
|
-
gemspec:validate
|
|
12
|
-
git:release
|
|
13
|
-
github:release
|
|
14
|
-
install
|
|
15
|
-
rcov
|
|
16
|
-
rdoc
|
|
17
|
-
release
|
|
18
|
-
rerdoc
|
|
19
|
-
spec
|
|
20
|
-
version
|
|
21
|
-
version:bump:major
|
|
22
|
-
version:bump:minor
|
|
23
|
-
version:bump:patch
|
|
24
|
-
version:write
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require 'rails/generators'
|
|
2
|
-
|
|
3
|
-
class GenesisGenerator < Rails::Generators::Base
|
|
4
|
-
#source_root File.join( File.dirname(__FILE__), 'templates' )
|
|
5
|
-
argument :seed_name, :type => :string
|
|
6
|
-
argument :env, :type => :string, :default => ''
|
|
7
|
-
|
|
8
|
-
def self.source_root
|
|
9
|
-
File.join( File.dirname(__FILE__), 'templates' )
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def install_seed
|
|
13
|
-
template "migration.erb", "db/seeds/#{env_str}#{timestamp}_#{file_name}.rb"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def file_name
|
|
19
|
-
seed_name.underscore
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def class_name
|
|
23
|
-
seed_name.camelcase
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def timestamp
|
|
27
|
-
DateTime.now.strftime( "%Y%m%d%H%M%S" )
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def env_str
|
|
31
|
-
return env.blank? ? '' : "#{env}/"
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require 'rails/generators'
|
|
2
|
-
|
|
3
|
-
class GenesisContextsGenerator < Rails::Generators::Base
|
|
4
|
-
argument :contexts, :type => :string, :default => []
|
|
5
|
-
|
|
6
|
-
def self.source_root
|
|
7
|
-
File.join( File.dirname(__FILE__), 'templates' )
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def install_contexts
|
|
11
|
-
@contexts.each { |context| empty_directory "#{Genesis::SEEDS_ROOT}/contexts/#{context}" }
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'rails/generators'
|
|
2
|
-
|
|
3
|
-
class PrepareGenesisGenerator < Rails::Generators::Base
|
|
4
|
-
argument :envs, :type => :string, :default => %w(development production)
|
|
5
|
-
|
|
6
|
-
def self.source_root
|
|
7
|
-
File.join( File.dirname(__FILE__), 'templates' )
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def install_seeding
|
|
11
|
-
envs.each { |env| empty_directory "db/seeds/#{env}" }
|
|
12
|
-
copy_file 'genesis.rake', 'lib/tasks/genesis.rake'
|
|
13
|
-
copy_file 'genesis_callbacks.rb', 'db/seeds/genesis_callbacks.rb'
|
|
14
|
-
end
|
|
15
|
-
end
|
|
File without changes
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
class GenesisGenerator < Rails::Generator::NamedBase
|
|
2
|
-
attr_accessor :opts
|
|
3
|
-
attr_accessor :environment
|
|
4
|
-
attr_accessor :env_dirs
|
|
5
|
-
attr_accessor :stamp
|
|
6
|
-
|
|
7
|
-
def initialize( runtime_args, runtime_options={} )
|
|
8
|
-
super
|
|
9
|
-
@opts = {}
|
|
10
|
-
@env_dirs = []
|
|
11
|
-
@stamp = DateTime.now.strftime( "%Y%m%d%H%M%S" )
|
|
12
|
-
parse_args( args )
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def manifest
|
|
16
|
-
env_str = @environment.nil? || @environment.empty? ? '' : "#{@environment}/"
|
|
17
|
-
|
|
18
|
-
record do |m|
|
|
19
|
-
m.directory "db/seeds"
|
|
20
|
-
@env_dirs.each { |env_dir| m.directory "db/seeds/#{env_dirs}" }
|
|
21
|
-
m.template "migration.rb", "db/seeds/#{env_str}#{@stamp}_#{file_name.underscore}.rb"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def parse_args( arguments )
|
|
28
|
-
arguments.each do |arg|
|
|
29
|
-
arg_parts = arg.split( ':' )
|
|
30
|
-
if arg_parts.size > 1
|
|
31
|
-
process_keyed_arg( arg_parts )
|
|
32
|
-
else
|
|
33
|
-
handle_env_arg( arg )
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def process_keyed_arg( arg_parts )
|
|
39
|
-
if arg_parts[0] == 'env'
|
|
40
|
-
handle_env_arg( arg_parts[1] )
|
|
41
|
-
else
|
|
42
|
-
opts[arg_parts[0].to_sym] = arg_parts[1]
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def handle_env_arg( val )
|
|
47
|
-
@environment = val
|
|
48
|
-
@env_dirs = val
|
|
49
|
-
end
|
|
50
|
-
end
|
|
File without changes
|
|
File without changes
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
class GenesisContextsGenerator < Rails::Generator::Base
|
|
2
|
-
attr_accessor :opts
|
|
3
|
-
attr_accessor :environments
|
|
4
|
-
|
|
5
|
-
def initialize( runtime_args, runtime_options={} )
|
|
6
|
-
super
|
|
7
|
-
@opts = {}
|
|
8
|
-
@contexts = []
|
|
9
|
-
parse_args( args )
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def manifest
|
|
13
|
-
record do |m|
|
|
14
|
-
m.directory Genesis::SEEDS_ROOT
|
|
15
|
-
@contexts.each { |context| m.directory "#{Genesis::SEEDS_ROOT}/contexts/#{context}" }
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def parse_args( arguments )
|
|
22
|
-
arguments.each do |arg|
|
|
23
|
-
arg_parts = arg.split( ':' )
|
|
24
|
-
if arg_parts[0] == 'contexts'
|
|
25
|
-
handle_env_arg( arg_parts[1] )
|
|
26
|
-
else
|
|
27
|
-
opts[arg_parts[0].to_sym] = arg_parts[1]
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def handle_contexts_arg( val )
|
|
33
|
-
if val.include?( '[' ) && val.include?( ']')
|
|
34
|
-
val.gsub!( /\[/, '' ).gsub!( /\]/, '' )
|
|
35
|
-
val.split( ',' ).each { |v| @contexts << v.trim.gsub( /,/, '' ) }
|
|
36
|
-
elsif val.include?( '[' ) || val.include?( ']' )
|
|
37
|
-
raise 'Error The contexts option must be formatted without any spaces in the array. ie. contexts:[accounts,users]'
|
|
38
|
-
elsif val.include?( ',' )
|
|
39
|
-
raise 'Error The contexts option must be formatted with braces at the beginning and end of the list. ie. contexts:[accounts,users]'
|
|
40
|
-
else
|
|
41
|
-
@contexts << val
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
script/generate seed create_users OR script/generate seed create_users production
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
class PrepareSeedingGenerator < Rails::Generator::Base
|
|
2
|
-
attr_accessor :opts
|
|
3
|
-
attr_accessor :environments
|
|
4
|
-
|
|
5
|
-
def initialize( runtime_args, runtime_options = {} )
|
|
6
|
-
super
|
|
7
|
-
@opts = {}
|
|
8
|
-
@environments = []
|
|
9
|
-
parse_args( args )
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def manifest
|
|
13
|
-
record do |m|
|
|
14
|
-
m.directory 'db/seeds'
|
|
15
|
-
@environments.each { |env| m.directory "db/seeds/#{env}" }
|
|
16
|
-
m.file 'genesis.rake', 'lib/tasks/genesis.rake'
|
|
17
|
-
m.file 'genesis_callbacks.rb', 'db/seeds/genesis_callbacks.rb'
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
def parse_args( arguments )
|
|
24
|
-
arguments.each do |arg|
|
|
25
|
-
arg_parts = arg.split( ':' )
|
|
26
|
-
if arg_parts[0] == 'env'
|
|
27
|
-
handle_env_arg( arg_parts[1] )
|
|
28
|
-
else
|
|
29
|
-
opts[arg_parts[0].to_sym] = arg_parts[1]
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
validate_env_args
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def handle_env_arg( val )
|
|
37
|
-
if val.include?( '[' ) && val.include?( ']')
|
|
38
|
-
val.gsub!( /\[/, '' ).gsub!( /\]/, '' )
|
|
39
|
-
val.split( ',' ).each { |v| @environments << v.trim.gsub( /,/, '' ) }
|
|
40
|
-
elsif val.include?( '[' ) || val.include?( ']' )
|
|
41
|
-
raise 'Error The env option must be formatted without any spaces in the array. ie. env:[development,production]'
|
|
42
|
-
elsif val.include?( ',' )
|
|
43
|
-
raise 'Error The env option must be formatted with braces at the beginning and end of the list. ie. env:[development,production]'
|
|
44
|
-
else
|
|
45
|
-
@environments << val
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def validate_env_args
|
|
50
|
-
@environments += %w(development production) if @environments.empty?
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'generators/genesis/genesis_generator'
|
|
3
|
-
|
|
4
|
-
describe GenesisGenerator do
|
|
5
|
-
|
|
6
|
-
before :each do
|
|
7
|
-
@destination = File.join 'tmp', 'test_app'
|
|
8
|
-
@source = GenesisGenerator.source_root
|
|
9
|
-
GenesisGenerator.start '', :destination_root => @destination
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
after :each do
|
|
13
|
-
FileUtils.rm_rf @destination
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
{}.each do |file, path|
|
|
17
|
-
it "should copy '#{file}' to '#{path}'" do
|
|
18
|
-
File.exists?( File.join( @destination, path ) ).should be_true
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# it "should agree that the contents of '#{file}' are identical to '#{path}'" do
|
|
22
|
-
# File.read( File.join( @source, file ) ).should eql File.read( File.join( @destination, path ) )
|
|
23
|
-
# end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|