Class: Arli::Actions::DirName

Inherits:
Action
  • Object
show all
Defined in:
lib/arli/actions/dir_name.rb

Overview

The purpose of this action is to fix the directory name of the library, that’s possibly incorrect. For example, library “Adafruit Unified Sensor” installs into the folder ‘Adafruit_Unified_Sensor’ while the source files inside are ‘Adafruit_Sensor.h’ This action renames invalid library folders based on the source files found inside.

Constant Summary

Constants included from Helpers::Output

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

Instance Attribute Summary collapse

Attributes inherited from Action

#config, #library

Instance Method Summary collapse

Methods inherited from Action

inherited, #initialize, #mv, #run!, #supported?, #to_s

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

This class inherits a constructor from Arli::Actions::Action

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



16
17
18
# File 'lib/arli/actions/dir_name.rb', line 16

def headers
  @headers
end

#sourcesObject

Returns the value of attribute sources.



16
17
18
# File 'lib/arli/actions/dir_name.rb', line 16

def sources
  @sources
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/arli/actions/dir_name.rb', line 18

def execute
  find_source_files

  # so "dir" is the 'Adafruit_Unified_Sensor'
  # but we found header Adafruit_Sensor we should
  # rename the folder

  if headers.include?(dir) || sources.include?(dir)
    set_canonical_dir!(dir)
  else
    candidate =
        if_only_one(headers) ||
            if_only_one(sources) ||
            if_header_a_substring(headers)

    set_canonical_dir!(candidate)
  end

  if if_no(sources) && if_have(headers)
    library.headers_only = true
  end
end