Class: Arli::Actions::Action

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helpers::Inherited, Helpers::Output
Defined in:
lib/arli/actions/action.rb

Overview

Represents an abstract action related to the library

Direct Known Subclasses

DirName, GitRepo, MoveToLibraryPath, UnzipFile

Constant Summary

Constants included from Helpers::Output

Helpers::Output::CHAR_FAILURE, Helpers::Output::CHAR_SUCCESS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Inherited

included

Methods included from Helpers::Output

#___, #__p, #__pf, #__pt, #abort?, #action_fail, #action_ok, #backup?, #cursor, #debug, #debug?, disable!, enable!, enabled?, #error, #fuck, #header, #hr, #indent_cursor, #info, #ok, #overwrite?, #print_action_failure, #print_action_starting, #print_action_success, #print_target_dir, #quiet?, #raise_invalid_arli_command!, #report_exception, #verbose?

Constructor Details

#initialize(library, config: Arli.config) ⇒ Action

Returns a new instance of Action.



28
29
30
31
# File 'lib/arli/actions/action.rb', line 28

def initialize(library, config: Arli.config)
  self.library = library
  self.config  = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



26
27
28
# File 'lib/arli/actions/action.rb', line 26

def config
  @config
end

#libraryObject

Returns the value of attribute library.



26
27
28
# File 'lib/arli/actions/action.rb', line 26

def library
  @library
end

Class Method Details

.inherited(base) ⇒ Object



21
22
23
# File 'lib/arli/actions/action.rb', line 21

def inherited(base)
  ::Arli::Actions.actions[base.short_name] = base
end

Instance Method Details

#mv(from, to) ⇒ Object



48
49
50
# File 'lib/arli/actions/action.rb', line 48

def mv(from, to)
  FileUtils.mv(from, to)
end

#run!Object



33
34
35
36
37
# File 'lib/arli/actions/action.rb', line 33

def run!
  execute
rescue Exception => e
  action_fail(self, e)
end

#supported?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/arli/actions/action.rb', line 39

def supported?
  return @supported if defined?(@supported)
  if self.class.check_command && self.class.check_pattern
    @supported = (`#{self.class.check_command} 2>/dev/null | grep "#{self.class.check_pattern}"`.chomp != '')
  else
    @supported = true
  end
end

#to_sObject



52
53
54
# File 'lib/arli/actions/action.rb', line 52

def to_s
  "<Action:#{(Arli::Actions.action_name(self) || 'unknown action').bold.blue}: lib=#{library.name}>"
end