Class: FoodCourt::Command
- Inherits:
-
Object
- Object
- FoodCourt::Command
- Defined in:
- lib/food_court/command.rb
Constant Summary collapse
- TEMPLATE_PATH =
File.join( File.dirname(__FILE__), '/../../', 'stacks' )
Instance Attribute Summary collapse
-
#current_path ⇒ Object
readonly
Returns the value of attribute current_path.
Instance Method Summary collapse
- #bootstrap(bootstrap_file = nil) ⇒ Object
- #create_cookbook(name, dir = current_path) ⇒ Object
- #help ⇒ Object
- #init(template = 'nginx-passenger-ree') ⇒ Object
-
#initialize(*args) ⇒ Command
constructor
A new instance of Command.
- #update(update_config = nil) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 15 16 17 |
# File 'lib/food_court/command.rb', line 9 def initialize(*args) @current_path = Dir.pwd command = args.shift if self.respond_to? command.to_sym self.send command, *args else self.help end end |
Instance Attribute Details
#current_path ⇒ Object (readonly)
Returns the value of attribute current_path.
6 7 8 |
# File 'lib/food_court/command.rb', line 6 def current_path @current_path end |
Instance Method Details
#bootstrap(bootstrap_file = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/food_court/command.rb', line 28 def bootstrap( bootstrap_file = nil ) # Provide your own sprinkle config or use the default one to bootstrap your slice. bootstrap_file ||= File.join(File.dirname(__FILE__), 'bootstrap.rb') # Sprinkle::OPTIONS[:force] = true raise 'a bootstrap.rb file is required for bootstrapping, please run "food_court init"' unless File.exists?( 'config/chef/bootstrap.rb' ) Sprinkle::OPTIONS[:verbose] = true # Sprinkle::OPTIONS[:test] = true Sprinkle::Script.sprinkle( File.read( bootstrap_file ) ) end |
#create_cookbook(name, dir = current_path) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/food_court/command.rb', line 53 def create_cookbook(name, dir=current_path) raise "Must provide a name" unless name puts "** Creating cookbook #{name}" FileUtils.mkdir_p File.join(dir, 'config/chef/site-cookbooks', name, "attributes") FileUtils.mkdir_p File.join(dir, 'config/chef/site-cookbooks', name, "recipes") FileUtils.mkdir_p File.join(dir, 'config/chef/site-cookbooks', name, "definitions") FileUtils.mkdir_p File.join(dir, 'config/chef/site-cookbooks', name, "libraries") FileUtils.mkdir_p File.join(dir, 'config/chef/site-cookbooks', name, "files", "default") FileUtils.mkdir_p File.join(dir, 'config/chef/site-cookbooks', name, "stacks", "default") unless File.exists?(File.join(dir, 'config/chef/site-cookbooks', name, "recipes", "default.rb")) File.open(File.join(dir, 'config/chef/site-cookbooks', name, "recipes", "default.rb"), "w") do |file| file.puts <<-EOH # # Cookbook Name:: #{name} # Recipe:: default # # Copyright #{Time.now.year}, MY_COMPANY # EOH end end end |
#help ⇒ Object
49 50 51 |
# File 'lib/food_court/command.rb', line 49 def help puts File.read(File.join(File.dirname(__FILE__), '../../README.rdoc')) end |
#init(template = 'nginx-passenger-ree') ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/food_court/command.rb', line 19 def init(template='nginx-passenger-ree') puts "Setting up current directory for #{template} stack" FileUtils.mkdir_p File.join(current_path, 'config/chef') FileUtils.mkdir_p File.join(current_path, 'config/chef/deployments') FileUtils.mkdir_p File.join(current_path, 'config/chef/site-cookbooks') FileUtils.cp File.join(TEMPLATE_PATH, template, 'order.rb'), File.join(current_path, 'config/chef', 'order.rb') FileUtils.cp File.join(TEMPLATE_PATH, template, 'bootstrap.rb'), File.join(current_path, 'config/chef', 'bootstrap.rb') end |
#update(update_config = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/food_court/command.rb', line 38 def update( update_config = nil ) # Provide your own sprinkle config or use the default one to update_slice your slice. update_config ||= File.join(File.dirname(__FILE__), 'update_slice.rb') # Sprinkle::OPTIONS[:force] = true raise 'a update_slice.rb file is required for updating the chef configuration on your slice, please run "food_court update"' unless File.exists?( 'config/chef/bootstrap.rb' ) Sprinkle::OPTIONS[:verbose] = true # Sprinkle::OPTIONS[:test] = true Sprinkle::Script.sprinkle( File.read( update_config ) ) end |