Class: GitShizzle::Dsl::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/git_shizzle/dsl/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/git_shizzle/dsl/command.rb', line 5

def description
  @description
end

#identifierObject (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