Class: Beet::Executor
- Inherits:
-
Object
- Object
- Beet::Executor
- Includes:
- Capistrano, CommandExecution, FileSystem, Interaction, Rails, SCM
- Defined in:
- lib/beet/executor.rb
Constant Summary collapse
- BEET_DATA_FILE =
"~/.beet.yml"
Instance Attribute Summary collapse
-
#gems ⇒ Object
Returns the value of attribute gems.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#recipes ⇒ Object
Returns the value of attribute recipes.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#ruby_version ⇒ Object
Returns the value of attribute ruby_version.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#todo_items ⇒ Object
Returns the value of attribute todo_items.
Instance Method Summary collapse
-
#initialize(project_name, options = {}) ⇒ Executor
constructor
:nodoc:.
- #log(*args) ⇒ Object
- #run_recipes ⇒ Object
- #start ⇒ Object
- #todo(string = nil, &block) ⇒ Object
Methods included from SCM
Methods included from Capistrano
Methods included from Rails
#environment, #freeze!, #gem, #gem_group, #gemfile, #generate, #initializer, #plugin, #route, #vendor
Methods included from Interaction
Methods included from FileSystem
#add_after, #add_after_or_append, #add_before, #append_file, #file, #gsub_file, #in_root, #inside, #lib, #rakefile
Methods included from CommandExecution
#rake, #run, #run_ruby_script, #rvm, #sudo
Constructor Details
#initialize(project_name, options = {}) ⇒ Executor
:nodoc:
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/beet/executor.rb', line 25 def initialize(project_name, ={}) # :nodoc: @root = calculate_project_root(project_name) @project_name = ((project_name == '.') ? File.basename(Dir.pwd) : project_name) @logger = Beet::Logger.new @gems = [] @template = [:template] @options = @todo_items = '' @recipes = [] @project_type = ([:project_type] && [:project_type].to_sym) || :rails3 @generate = true unless [:generate] == false @display = [:display] end |
Instance Attribute Details
#gems ⇒ Object
Returns the value of attribute gems.
23 24 25 |
# File 'lib/beet/executor.rb', line 23 def gems @gems end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
22 23 24 |
# File 'lib/beet/executor.rb', line 22 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/beet/executor.rb', line 22 def @options end |
#project_name ⇒ Object
Returns the value of attribute project_name.
23 24 25 |
# File 'lib/beet/executor.rb', line 23 def project_name @project_name end |
#recipes ⇒ Object
Returns the value of attribute recipes.
23 24 25 |
# File 'lib/beet/executor.rb', line 23 def recipes @recipes end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
22 23 24 |
# File 'lib/beet/executor.rb', line 22 def root @root end |
#ruby_version ⇒ Object
Returns the value of attribute ruby_version.
23 24 25 |
# File 'lib/beet/executor.rb', line 23 def ruby_version @ruby_version end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
22 23 24 |
# File 'lib/beet/executor.rb', line 22 def template @template end |
#todo_items ⇒ Object
Returns the value of attribute todo_items.
23 24 25 |
# File 'lib/beet/executor.rb', line 23 def todo_items @todo_items end |
Instance Method Details
#log(*args) ⇒ Object
106 107 108 |
# File 'lib/beet/executor.rb', line 106 def log(*args) logger.log(*args) end |
#run_recipes ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/beet/executor.rb', line 91 def run_recipes @recipes.each do |recipe| begin code = open(recipe).read if @display puts code else in_root { instance_eval(code)} end rescue LoadError, Errno::ENOENT => e raise "The recipe [#{recipe}] could not be loaded. Error: #{e}" end end end |
#start ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/beet/executor.rb', line 40 def start if [:use] puts "Loading saved configuration: #{@options[:use]}" data = load_saved_recipe_file if config = data[@options[:use]] @gems.concat(config[:gems]) if config[:gems] @template = config[:template] if config[:template] @recipes.concat(config[:recipes]) if config[:recipes] end end if @display && @template puts open(TEMPLATE_LOCATIONS[@template]).read else if @generate # TODO maybe let people specify path to rails 3 script rather than just assume its 'rails' if @project_type == :rails3 puts "Generating rails 3 project #{project_name}..." if @template system("rails new #{project_name} -m #{TEMPLATE_LOCATIONS[@template]}") else system("rails new #{project_name}") end else unless rails2_version = search_for_rails_2 puts "Please create a rails2 command which points to rails 2.x executable." exit else puts "Generating rails project #{project_name}..." if @template system("rails _#{rails2_version}_ #{project_name} -m #{TEMPLATE_LOCATIONS[@template]}") else system("rails _#{rails2_version}_ #{project_name}") end end end end add_gems print_todo if [:save] save_run end end run_recipes end |
#todo(string = nil, &block) ⇒ Object
110 111 112 |
# File 'lib/beet/executor.rb', line 110 def todo(string=nil, &block) self.todo_items << (string || block.call) end |