Class: Beet::Executor

Inherits:
Object
  • Object
show all
Includes:
Capistrano, Execution, FileSystem, Interaction, Rails, SCM
Defined in:
lib/beet/executor.rb

Constant Summary collapse

BEET_DATA_FILE =
"~/.beet.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SCM

#git

Methods included from Capistrano

#capify!

Methods included from Rails

#environment, #freeze!, #gem, #generate, #initializer, #plugin, #route, #vendor

Methods included from Interaction

#ask, #no?, #yes?

Methods included from FileSystem

#add_after, #add_before, #append_file, #file, #gsub_file, #in_root, #inside, #lib, #rakefile

Methods included from Execution

#rake, #run, #run_ruby_script, #sudo

Constructor Details

#initialize(project_name, options = {}) ⇒ Executor

:nodoc:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/beet/executor.rb', line 18

def initialize(project_name, options={}) # :nodoc:
  @root = calculate_project_root(project_name)
  @project_name = ((project_name == '.') ? File.basename(Dir.pwd) : project_name)
  @logger = Beet::Logger.new
  @gems = []
  @template = options[:template]
  @options = options
  @todo_items = ''
  @recipes = []
  @project_type = options[:project_type]
  @generate = true unless options[:generate] == false
  @display = options[:display]
  extract_commands_from_options
end

Instance Attribute Details

#gemsObject

Returns the value of attribute gems.



16
17
18
# File 'lib/beet/executor.rb', line 16

def gems
  @gems
end

#loggerObject (readonly)

Returns the value of attribute logger.



15
16
17
# File 'lib/beet/executor.rb', line 15

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/beet/executor.rb', line 15

def options
  @options
end

#project_nameObject

Returns the value of attribute project_name.



16
17
18
# File 'lib/beet/executor.rb', line 16

def project_name
  @project_name
end

#recipesObject

Returns the value of attribute recipes.



16
17
18
# File 'lib/beet/executor.rb', line 16

def recipes
  @recipes
end

#rootObject (readonly)

Returns the value of attribute root.



15
16
17
# File 'lib/beet/executor.rb', line 15

def root
  @root
end

#templateObject (readonly)

Returns the value of attribute template.



15
16
17
# File 'lib/beet/executor.rb', line 15

def template
  @template
end

#todo_itemsObject

Returns the value of attribute todo_items.



16
17
18
# File 'lib/beet/executor.rb', line 16

def todo_items
  @todo_items
end

Instance Method Details

#log(*args) ⇒ Object



87
88
89
# File 'lib/beet/executor.rb', line 87

def log(*args)
  logger.log(*args)
end

#run_recipesObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/beet/executor.rb', line 72

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

#startObject



33
34
35
36
37
38
39
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
# File 'lib/beet/executor.rb', line 33

def start
  if @options[: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
    case @project_type
    when :rails
      if @generate
        puts "Generating rails project #{project_name}..."
        if @template
          system("rails #{project_name} -m #{TEMPLATE_LOCATIONS[@template]}")
        else
          system("rails #{project_name}")
        end
      end
    end

    add_gems

    print_todo

    if @options[:save]
      save_run
    end
  end

  run_recipes

end

#todo(string = nil, &block) ⇒ Object



91
92
93
# File 'lib/beet/executor.rb', line 91

def todo(string=nil, &block)
  self.todo_items << (string || block.call)
end