Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jason Harrelson
committed
Sep 19, 2010
1 parent
853fb81
commit 3dbfb64
Showing
4 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
lib/generators/genesis_contexts/genesis_contexts_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rails/generators' | ||
|
||
class GenesisContextsGenerator < Rails::Generators::Base | ||
argument :contexts, :type => :string, :default => [] | ||
|
||
def self.source_root | ||
File.join( File.dirname(__FILE__), 'templates' ) | ||
end | ||
|
||
def install_contexts | ||
@contexts.each { |context| empty_directory "#{Genesis::SEEDS_ROOT}/contexts/#{context}" } | ||
end | ||
end |
Empty file.
44 changes: 44 additions & 0 deletions
44
rails_generators/genesis_contexts/genesis_contexts_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class GenesisContextsGenerator < Rails::Generator::Base | ||
attr_accessor :opts | ||
attr_accessor :environments | ||
|
||
def initialize( runtime_args, runtime_options={} ) | ||
super | ||
@opts = {} | ||
@contexts = [] | ||
parse_args( args ) | ||
end | ||
|
||
def manifest | ||
record do |m| | ||
m.directory Genesis::SEEDS_ROOT | ||
@contexts.each { |context| m.directory "#{Genesis::SEEDS_ROOT}/contexts/#{context}" } | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse_args( arguments ) | ||
arguments.each do |arg| | ||
arg_parts = arg.split( ':' ) | ||
if arg_parts[0] == 'contexts' | ||
handle_env_arg( arg_parts[1] ) | ||
else | ||
opts[arg_parts[0].to_sym] = arg_parts[1] | ||
end | ||
end | ||
end | ||
|
||
def handle_contexts_arg( val ) | ||
if val.include?( '[' ) && val.include?( ']') | ||
val.gsub!( /\[/, '' ).gsub!( /\]/, '' ) | ||
val.split( ',' ).each { |v| @contexts << v.trim.gsub( /,/, '' ) } | ||
elsif val.include?( '[' ) || val.include?( ']' ) | ||
raise 'Error The contexts option must be formatted without any spaces in the array. ie. contexts:[accounts,users]' | ||
elsif val.include?( ',' ) | ||
raise 'Error The contexts option must be formatted with braces at the beginning and end of the list. ie. contexts:[accounts,users]' | ||
else | ||
@contexts << val | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters