Class: PGit::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/pgit/command.rb,
lib/pgit/command/add.rb,
lib/pgit/command/run.rb,
lib/pgit/command/edit.rb,
lib/pgit/command/show.rb,
lib/pgit/command/remove.rb,
lib/pgit/command/application.rb

Defined Under Namespace

Classes: Add, Application, Edit, Remove, Run, Show

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, steps, project) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
# File 'lib/pgit/command.rb', line 5

def initialize(name, steps, project)
  @name = name
  @steps = steps
  @branch_name = PGit::CurrentBranch.new.name
  @current_project = project
end

Instance Attribute Details

#branch_nameObject (readonly)

Returns the value of attribute branch_name.



3
4
5
# File 'lib/pgit/command.rb', line 3

def branch_name
  @branch_name
end

#current_projectObject (readonly)

Returns the value of attribute current_project.



3
4
5
# File 'lib/pgit/command.rb', line 3

def current_project
  @current_project
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/pgit/command.rb', line 3

def name
  @name
end

#stepsObject (readonly)

Returns the value of attribute steps.



3
4
5
# File 'lib/pgit/command.rb', line 3

def steps
  @steps
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pgit/command.rb', line 12

def execute
  @steps.each do |step|
    step.gsub!(/STORY_BRANCH/, branch_name)

    puts "About to execute '#{formatted_step(step)}'. Proceed? #{exec_options}"
    response = STDIN.gets.chomp

    if response.letter?('s')
      puts formatted_action('Skipping...')
    elsif response.letter?('q')
      puts formatted_action("Quitting...")
      break
    elsif response.letter?('y')
      puts "#{formatted_action('Executing')} '#{formatted_step(step)}'..."
      puts `#{step}`
    else
      show_options
      raise PGit::Error::User
    end
  end
rescue PGit::Error::User
  retry
end

#remove!Object



54
55
56
57
# File 'lib/pgit/command.rb', line 54

def remove!
  current_project.commands.reject! {|cmd| cmd.name == name}
  current_project.save!
end

#save!Object



48
49
50
51
52
# File 'lib/pgit/command.rb', line 48

def save!
  current_project.commands.reject! {|cmd| cmd.name == name}
  current_project.commands = current_project.commands << self
  current_project.save!
end

#to_hObject



36
37
38
# File 'lib/pgit/command.rb', line 36

def to_h
  to_hash
end

#to_hashObject



40
41
42
# File 'lib/pgit/command.rb', line 40

def to_hash
  { name => steps }
end

#to_sObject



44
45
46
# File 'lib/pgit/command.rb', line 44

def to_s
  steps.inject(Rainbow("#{name}:\n").bright) {|accum, step| accum + "  #{step}\n" }
end