Class: Toys::Definition::Alias

Inherits:
Object
  • Object
show all
Defined in:
lib/toys/definition/alias.rb

Overview

An alias is a name that refers to another name.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loader, full_name, target, priority) ⇒ Alias

Create a new alias.

Parameters:

  • full_name (Array<String>)

    The name of the alias.

  • target (String, Array<String>)

    The name of the target. May either be a local reference (a single string) or a global reference (an array of strings)



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/toys/definition/alias.rb', line 46

def initialize(loader, full_name, target, priority)
  @target_name =
    if target.is_a?(::Array)
      target.map(&:to_s)
    else
      full_name[0..-2] + [target.to_s]
    end
  @target_name.freeze
  @full_name = full_name.map(&:to_s).freeze
  @priority = priority
  @tool_class = DSL::Tool.new_class(@full_name, priority, loader)
end

Instance Attribute Details

#full_nameArray<String> (readonly)

Return the name of the tool as an array of strings. This array may not be modified.

Returns:

  • (Array<String>)


70
71
72
# File 'lib/toys/definition/alias.rb', line 70

def full_name
  @full_name
end

#priorityInteger (readonly)

Return the priority of this alias.

Returns:

  • (Integer)


76
77
78
# File 'lib/toys/definition/alias.rb', line 76

def priority
  @priority
end

#target_nameArray<String> (readonly)

Return the name of the target as an array of strings. This array may not be modified.

Returns:

  • (Array<String>)


83
84
85
# File 'lib/toys/definition/alias.rb', line 83

def target_name
  @target_name
end

#tool_classClass (readonly)

Return the tool class.

Returns:

  • (Class)


63
64
65
# File 'lib/toys/definition/alias.rb', line 63

def tool_class
  @tool_class
end

Instance Method Details

#display_nameString

Returns a displayable name of this tool, generally the full name delimited by spaces.

Returns:

  • (String)


98
99
100
# File 'lib/toys/definition/alias.rb', line 98

def display_name
  full_name.join(" ")
end

#display_targetString

Returns a displayable name of the target, generally the full name delimited by spaces.

Returns:

  • (String)


107
108
109
# File 'lib/toys/definition/alias.rb', line 107

def display_target
  target_name.join(" ")
end

#simple_nameString

Returns the local name of this tool.

Returns:

  • (String)


89
90
91
# File 'lib/toys/definition/alias.rb', line 89

def simple_name
  full_name.last
end