Class: PGit::Command
- Inherits:
-
Object
- Object
- PGit::Command
- 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
-
#branch_name ⇒ Object
readonly
Returns the value of attribute branch_name.
-
#current_project ⇒ Object
readonly
Returns the value of attribute current_project.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(name, steps, project) ⇒ Command
constructor
A new instance of Command.
- #remove! ⇒ Object
- #save! ⇒ Object
- #to_h ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
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_name ⇒ Object (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_project ⇒ Object (readonly)
Returns the value of attribute current_project.
3 4 5 |
# File 'lib/pgit/command.rb', line 3 def current_project @current_project end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/pgit/command.rb', line 3 def name @name end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
3 4 5 |
# File 'lib/pgit/command.rb', line 3 def steps @steps end |
Instance Method Details
#execute ⇒ Object
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? #{}" 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 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_h ⇒ Object
36 37 38 |
# File 'lib/pgit/command.rb', line 36 def to_h to_hash end |
#to_hash ⇒ Object
40 41 42 |
# File 'lib/pgit/command.rb', line 40 def to_hash { name => steps } end |
#to_s ⇒ Object
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 |