Class: Bashly::Script::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/bashly/script/dependency.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label: nil, commands: nil, help: nil) ⇒ Dependency

Returns a new instance of Dependency.



27
28
29
30
31
# File 'lib/bashly/script/dependency.rb', line 27

def initialize(label: nil, commands: nil, help: nil)
  @label = label
  @commands = commands.is_a?(String) ? [commands] : commands
  @help = help&.empty? ? nil : help
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



4
5
6
# File 'lib/bashly/script/dependency.rb', line 4

def commands
  @commands
end

#helpObject (readonly)

Returns the value of attribute help.



4
5
6
# File 'lib/bashly/script/dependency.rb', line 4

def help
  @help
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/bashly/script/dependency.rb', line 4

def label
  @label
end

Class Method Details

.from_config(key, value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bashly/script/dependency.rb', line 11

def from_config(key, value)
  options = case value
  when nil
    { label: key, commands: key }
  when String
    { label: key, commands: key, help: value }
  when Hash
    { label: key, commands: value['command'], help: value['help'] }
  else
    {}
  end

  new(**options)
end

.option_keysObject



7
8
9
# File 'lib/bashly/script/dependency.rb', line 7

def option_keys
  @option_keys ||= %i[command help]
end

Instance Method Details

#multi?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bashly/script/dependency.rb', line 33

def multi?
  @multi ||= commands.size > 1
end

#nameObject



37
38
39
# File 'lib/bashly/script/dependency.rb', line 37

def name
  @name ||= multi? ? "#{label} (#{commands.join '/'})" : label
end