Class: Pione::Util::Completion

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/util/completion.rb

Direct Known Subclasses

BashCompletion, ZshCompletion

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#completion_commandObject (readonly)

Returns the value of attribute completion_command.



9
10
11
# File 'lib/pione/util/completion.rb', line 9

def completion_command
  @completion_command
end

#completion_execObject (readonly)

Returns the value of attribute completion_exec.



10
11
12
# File 'lib/pione/util/completion.rb', line 10

def completion_exec
  @completion_exec
end

#name2Object (readonly)

Returns the value of attribute name2.



11
12
13
# File 'lib/pione/util/completion.rb', line 11

def name2
  @name2
end

#name3Object (readonly)

Returns the value of attribute name3.



12
13
14
# File 'lib/pione/util/completion.rb', line 12

def name3
  @name3
end

Class Method Details

.compile(source, target) ⇒ Object



4
5
6
7
# File 'lib/pione/util/completion.rb', line 4

def self.compile(source, target)
  context = self.new.context
  target.write(ERB.new(source.read, nil, "-").result(context))
end

Instance Method Details

#contextObject



20
21
22
# File 'lib/pione/util/completion.rb', line 20

def context
  binding
end

#descendants(keys, cmd) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pione/util/completion.rb', line 24

def descendants(keys, cmd)
  if cmd.subcommand.empty?
    [[keys, cmd]]
  else
    cmd.subcommand.inject([[keys, cmd]]) do |list, (key, child)|
      _keys = keys + [key]
      if child.subcommand.empty?
        list << [_keys, child]
      else
        list.concat(descendants(_keys, child))
      end
    end
  end
end

#toplevel_commands(mod) ⇒ Object



14
15
16
17
18
# File 'lib/pione/util/completion.rb', line 14

def toplevel_commands(mod)
  mod.constants.map{|c| mod.const_get(c)}.select do |c|
    c.is_a?(Class) and c < Command::BasicCommand and c.toplevel?
  end.map {|cmd| [cmd.scenario_name, cmd]}
end