Class: Yap::Shell::Evaluation::ShellExpansions

Inherits:
Object
  • Object
show all
Defined in:
lib/yap/shell/evaluation/shell_expansions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world:, aliases: Aliases.instance) ⇒ ShellExpansions

Returns a new instance of ShellExpansions.



6
7
8
9
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 6

def initialize(world:, aliases: Aliases.instance)
  @world = world
  @aliases = aliases
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



4
5
6
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 4

def aliases
  @aliases
end

#worldObject (readonly)

Returns the value of attribute world.



4
5
6
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 4

def world
  @world
end

Instance Method Details

#expand_aliases_in(input) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 11

def expand_aliases_in(input)
  head, *tail = input.split(/\s/, 2).first
  if new_head=aliases.fetch_alias(head)
    [new_head].concat(tail).join(" ")
  else
    input
  end
end

#expand_variables_in(input) ⇒ Object



29
30
31
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 29

def expand_variables_in(input)
  env_expand(input)
end

#expand_words_in(input, escape_directory_expansions: true) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 20

def expand_words_in(input, escape_directory_expansions: true)
  [input].flatten.inject([]) do |results,str|
    results << process_expansions(
      word_expand(str),
      escape_directory_expansions: escape_directory_expansions
    )
  end.flatten
end