Class: Hyrb::Commands::Pipeline

Inherits:
Pipeline
  • Object
show all
Defined in:
lib/hyrb/command.rb

Instance Attribute Summary

Attributes inherited from Pipeline

#current_task, #env, #next_tasks, #prev_tasks

Instance Method Summary collapse

Methods inherited from Pipeline

#build_task_list, #invoke, rules, #run, #tsort_each_child, #tsort_each_node

Constructor Details

#initialize(task_class) ⇒ Pipeline

Returns a new instance of Pipeline.



22
23
24
25
26
27
# File 'lib/hyrb/command.rb', line 22

def initialize(task_class)
  super

  # Thor:Shell defines a constructor so have to do this here
  extend Thor::Shell
end

Instance Method Details

#beepObject



69
70
71
# File 'lib/hyrb/command.rb', line 69

def beep
  print "\a"
end

#edit(path) ⇒ Object



46
47
48
49
50
51
# File 'lib/hyrb/command.rb', line 46

def edit(path)
  editor = [ENV['VISUAL'], ENV['EDITOR']].find { |e| e.present? }
  raise "Please set $EDITOR variable :)" unless editor
  cmd = "#{editor} #{path}"
  raise "Could not run '#{cmd}'" unless system(cmd)
end

#info(message) ⇒ Object



65
66
67
# File 'lib/hyrb/command.rb', line 65

def info(message)
  say message
end

#option_list(cache, attribute = nil, default = nil, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/hyrb/command.rb', line 53

def option_list(cache, attribute = nil, default = nil, &block)
  list = attribute ? cache[attribute] : cache
  choices = list.map.with_index(&block)
  say choices.join("\n")
  index = ask("Pick from #{attribute}:", default: default)
  if index.try :include?, ","
    index.split(",").map { |i| list[i.to_i - 1] }
  else
    list[index.to_i - 1]
  end
end

#prompt(prompt, hash, key, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hyrb/command.rb', line 29

def prompt(prompt, hash, key, options = {})
  unless options.is_a?(Hash)
    default = options
    options = {}
    options[:default] = default
  end

  if options.delete(:always)
    options[:default] = hash[key] if hash[key]
    hash[key] = ask(prompt, options)
  else
    hash[key].blank? ? hash[key] = ask(prompt, options) : hash[key]
  end

  hash.save! if hash.respond_to? :save!
end