Class: VER::Executor::ExMethod

Inherits:
Entry show all
Defined in:
lib/ver/executor/method.rb

Constant Summary

Constants inherited from VER::Entry

VER::Entry::BACKWARD_WORD, VER::Entry::FORWARD_WORD

Instance Attribute Summary

Attributes inherited from Entry

#callback, #caller, #parent, #tabcount, #tree, #update_on_change, #ybar

Attributes included from Keymapped

#major_mode

Instance Method Summary collapse

Methods inherited from Entry

#cancel, #completed=, #completion, #destroy, #initialize, #next_line, #on_delete, #on_insert, #prev_line, #speed_selection, #subset, #sync_value_with_tree_selection, #update_items, #update_only

Methods included from Keymapped

#minor_mode, #minor_mode?

Methods inherited from VER::Entry

#beginning_of_history, #cursor=, #delete, #delete_next_char, #delete_next_word, #delete_prev_char, #delete_prev_word, #deleting, #end_of_history, #end_of_line, #error, #event, #events, #insert, #insert_selection, #insert_string, #insert_tab, #kill, #kill_end_of_line, #killing, #message, #next_char, #next_history, #next_word, #paste, #prev_char, #prev_word, #previous_history, #sel_end_of_line, #sel_next_char, #sel_next_word, #sel_prev_char, #sel_prev_word, #sel_start_of_line, #start_of_line, #style, #transpose_chars, #value=, #virtual_movement

Constructor Details

This class inherits a constructor from VER::Executor::Entry

Instance Method Details

#accept_line(event) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/ver/executor/method.rb', line 42

def accept_line(event)
  self.tabcount = 0
  return unless item = tree.selection.first
  id = item.options[:values].first.to_i
  return unless action = @actions[id]
  callback.destroy
  action.call(caller)
end

#action(id) ⇒ Object



51
52
53
54
55
# File 'lib/ver/executor/method.rb', line 51

def action(id)
  caller.message @actions[id].call(caller).inspect
rescue Exception => ex
  caller.warn ex.message
end

#after_updateObject



26
27
28
29
30
31
32
# File 'lib/ver/executor/method.rb', line 26

def after_update
  total = tree.winfo_width
  third = total / 3

  tree.column('method',    width: third, stretch: true)
  tree.column('signature', width: third * 2, stretch: true)
end

#choices(name) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ver/executor/method.rb', line 34

def choices(name)
  subset(name, @actions.map.with_index{|action, id|
    receiver = action.receiver || caller
    method = receiver.method(action.method)
    [id, method.name.to_s, signature_of(method)]
  }.compact, 1)
end

#setupObject



4
5
6
7
8
# File 'lib/ver/executor/method.rb', line 4

def setup
  @actions = caller.major_mode.actions.sort_by(&:method)

  setup_tree
end

#setup_treeObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/ver/executor/method.rb', line 10

def setup_tree
  tree.configure(
    show: [:headings],
    columns: %w[id method signature],
    displaycolumns: %w[method signature],
  )

  tree.heading('method', text: 'Method')
  tree.heading('signature', text: 'Signature')
end

#signature_of(method) ⇒ Object

TODO: Use YARD for this, my local clone is a bit dusty and broken. What I really want to do is extract @usage or similar, for now we use the signature because parsing all the docs is expensive.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ver/executor/method.rb', line 61

def signature_of(method)
  source_file, source_line = method.source_location
  return '' unless source_file && source_line

  File.open(source_file) do |io|
    needle = source_line - 1

    io.each_line.with_index do |line, index|
      return line.strip if needle == index
    end
  end

  return ''
rescue Errno::ENOENT # <gem_prelude>, eval, etc.
  return ''
end

#tree_selection_valueObject



21
22
23
24
# File 'lib/ver/executor/method.rb', line 21

def tree_selection_value
  return unless item = tree.selection.first
  item.options[:values][1]
end