class Leg::Commands::BaseCommand
Constants
- ERROR_MSG
Public Class Methods
inherited(subclass)
click to toggle source
# File lib/leg/commands/base_command.rb, line 11 def self.inherited(subclass) Leg::Commands::LIST << subclass end
name()
click to toggle source
# File lib/leg/commands/base_command.rb, line 7 def self.name; raise NotImplementedError; end
new(args, config)
click to toggle source
# File lib/leg/commands/base_command.rb, line 2 def initialize(args, config) @args = args @config = config end
summary()
click to toggle source
# File lib/leg/commands/base_command.rb, line 8 def self.summary; raise NotImplementedError; end
Public Instance Methods
current_or_latest_step()
click to toggle source
# File lib/leg/commands/base_command.rb, line 104 def current_or_latest_step current_step || latest_step end
current_step()
click to toggle source
# File lib/leg/commands/base_command.rb, line 94 def current_step if @config[:step_path] File.basename(@config[:step_path]) end end
latest_step()
click to toggle source
# File lib/leg/commands/base_command.rb, line 100 def latest_step steps.last end
needs!(*whats)
click to toggle source
# File lib/leg/commands/base_command.rb, line 48 def needs!(*whats) options = whats.pop if whats.last.is_a? Hash options ||= {} yes = Array(whats).flatten.map { |w| [w, true] } no = Array(options[:not]).map { |w| [w, false] } (yes + no).each do |what, v| valid = false case what when :config valid = true if @config when :config_title valid = true if @config[:title] when :steps_folder valid = true if File.exist?(File.join(@config[:path], "steps")) when :steps valid = true if steps.length > 0 when :repo valid = true if File.exist?(File.join(@config[:path], "repo")) when :diff valid = true if File.exist?(File.join(@config[:path], "steps.diff")) when :doc valid = true if File.exist?(File.join(@config[:path], "doc")) when :doc_out valid = true if File.exist?(File.join(@config[:path], "doc/html_out")) when :ftp valid = true if File.exist?(File.join(@config[:path], "ftp.yml")) else raise NotImplementedError end if valid != v puts "Error: " + ERROR_MSG[what][v.to_s.to_sym] exit! end end end
run()
click to toggle source
# File lib/leg/commands/base_command.rb, line 9 def run; raise NotImplementedError; end
select_step(step, &block)
click to toggle source
# File lib/leg/commands/base_command.rb, line 119 def select_step(step, &block) puts "Selecting step: #{step}" FileUtils.cd(step_path(step), &block) end
step_name(step)
click to toggle source
# File lib/leg/commands/base_command.rb, line 108 def step_name(step) parts = step.split('-') if parts.length > 1 parts[1..-1].join('-') end end
step_path(step)
click to toggle source
# File lib/leg/commands/base_command.rb, line 115 def step_path(step) File.join(@config[:path], "steps", step) end
steps()
click to toggle source
# File lib/leg/commands/base_command.rb, line 87 def steps @steps ||= Dir[File.join(@config[:path], "steps/*")].map do |f| name = File.basename(f) name if File.directory?(f) && name =~ /\A\d+(\.\d+)*(-\w+)*\z/ end.compact.sort_by { |s| s.split(".").map(&:to_i) }.reject { |s| s.to_i.zero? } end