Class: GitShizzle::Dsl::Command
- Inherits:
-
Object
- Object
- GitShizzle::Dsl::Command
- Defined in:
- lib/git_shizzle/dsl/command.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
- #applicable_files(git_status) ⇒ Object
-
#initialize(identifier, description, block) ⇒ Command
constructor
A new instance of Command.
- #invoke(git, files) ⇒ Object
- #paths_for(command_paths) ⇒ Object
- #set_action(block) ⇒ Object
- #set_filter(block) ⇒ Object
Constructor Details
#initialize(identifier, description, block) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 12 |
# File 'lib/git_shizzle/dsl/command.rb', line 7 def initialize(identifier, description, block) @identifier = identifier @description = description GitShizzle::Dsl::CommandContext.new(self).instance_eval &block end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/git_shizzle/dsl/command.rb', line 5 def description @description end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
5 6 7 |
# File 'lib/git_shizzle/dsl/command.rb', line 5 def identifier @identifier end |
Instance Method Details
#applicable_files(git_status) ⇒ Object
14 15 16 17 18 |
# File 'lib/git_shizzle/dsl/command.rb', line 14 def applicable_files(git_status) git_status.find_all do |file| @filter.call(file.index_status, file.work_tree_status, file.path) end end |
#invoke(git, files) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/git_shizzle/dsl/command.rb', line 20 def invoke(git, files) raise GitShizzle::IndexSpecifications::NoFilesError.new(@identifier) if files.empty? files. map { |file| @action.call(file.index_status, file.work_tree_status, file.path) }. group_by { |group| group[0] }. each_pair { |command, command_paths| git.command command, paths_for(command_paths) } end |
#paths_for(command_paths) ⇒ Object
29 30 31 |
# File 'lib/git_shizzle/dsl/command.rb', line 29 def paths_for(command_paths) command_paths.map { |a| a[1] } end |
#set_action(block) ⇒ Object
37 38 39 |
# File 'lib/git_shizzle/dsl/command.rb', line 37 def set_action(block) @action = block end |
#set_filter(block) ⇒ Object
33 34 35 |
# File 'lib/git_shizzle/dsl/command.rb', line 33 def set_filter(block) @filter = block end |