Class: Arli::Library::Installer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helpers::Output
Defined in:
lib/arli/library/installer.rb

Constant Summary

Constants included from Helpers::Output

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Constructor Details

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

Returns a new instance of Installer.



16
17
18
19
20
# File 'lib/arli/library/installer.rb', line 16

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

Instance Attribute Details

#configObject

Returns the value of attribute config.



14
15
16
# File 'lib/arli/library/installer.rb', line 14

def config
  @config
end

#libraryObject

Returns the value of attribute library.



14
15
16
# File 'lib/arli/library/installer.rb', line 14

def library
  @library
end

#temp_dirObject

Returns the value of attribute temp_dir.



14
15
16
# File 'lib/arli/library/installer.rb', line 14

def temp_dir
  @temp_dir
end

Instance Method Details

#actions(library) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/arli/library/installer.rb', line 61

def actions(library)
  actions = []
  # First, how do we get the library?
  actions << ((library.url =~ /\.zip$/i) ? :unzip_file : :git_repo)
  actions << :dir_name
  actions << :move_to_library_path
  actions.flatten
end

#installObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/arli/library/installer.rb', line 22

def install
  ___ "#{library.name.blue.bold} "
  if library.nil? && library.library.nil?
    ___ ' (no library) '
    fuck
  elsif library.url.nil?
    ___ ' (no url) '
    fuck
  else
    ___ "(#{library.version.yellow.bold}) " if library.version
    indent_cursor
    actions(library).each do |action|
      run_action(action)
    end
  end
  ___ "\n"
end

#run_action(action_name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/arli/library/installer.rb', line 40

def run_action(action_name)
  klass = Arli::Actions.action(action_name)
  if klass
    action = klass.new(library, config: config)
    if action.supported?
      print_action_starting(action_name.to_s) do
        action.run!
      end
      puts if verbose?
    else
      print_action_failure('unsupported', "missing pre-requisites: #{klass.command_name.bold.yellow} did not succeed")
    end
  else
    print_action_failure("#{action_name.red} not found")
  end
end

#verbose?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/arli/library/installer.rb', line 57

def verbose?
  config.verbose
end