Class: Uh::WM::ActionHandler

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/uh/wm/action_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wm, manager, layout) ⇒ ActionHandler

Returns a new instance of ActionHandler.



9
10
11
# File 'lib/uh/wm/action_handler.rb', line 9

def initialize(wm, manager, layout)
  @wm, @manager, @layout = wm, manager, layout
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/uh/wm/action_handler.rb', line 51

def method_missing(m, *args, &block)
  if respond_to? m
    meth = layout_method m
    log "#{@layout.class.name}##{meth} #{args.inspect}"
    begin
      @layout.send(meth, *args)
    rescue NoMethodError
      log_error "Layout does not implement `#{meth}'"
    end
  else
    super
  end
end

Instance Attribute Details

#layoutObject (readonly)

Returns the value of attribute layout.



7
8
9
# File 'lib/uh/wm/action_handler.rb', line 7

def layout
  @layout
end

Instance Method Details

#call(action) ⇒ Object



13
14
15
16
17
# File 'lib/uh/wm/action_handler.rb', line 13

def call(action)
  instance_exec &action
rescue LocalJumpError => e
  log_error "Action: #{e}"
end

#execute(command) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/uh/wm/action_handler.rb', line 24

def execute(command)
  log "Spawn `#{command}`"
  pid = fork do
    fork do
      Process.setsid
      begin
        exec command
      rescue Errno::ENOENT => e
        log_error "Spawn: #{e}"
      end
    end
  end
  Process.waitpid pid
end

#log_clientsObject



43
44
45
# File 'lib/uh/wm/action_handler.rb', line 43

def log_clients
  log "Clients:\n#{@manager.to_s.lines.map { |e| "  #{e}" }.join.chomp}"
end

#log_layoutObject



39
40
41
# File 'lib/uh/wm/action_handler.rb', line 39

def log_layout
  log "Layout:\n#{@layout.to_s.lines.map { |e| "  #{e}" }.join.chomp}"
end

#log_separatorObject



47
48
49
# File 'lib/uh/wm/action_handler.rb', line 47

def log_separator
  log '- ' * 24
end

#quitObject



19
20
21
22
# File 'lib/uh/wm/action_handler.rb', line 19

def quit
  log 'Exiting...'
  @wm.request_quit!
end

#respond_to_missing?(m) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/uh/wm/action_handler.rb', line 65

def respond_to_missing?(m, *)
  m.to_s =~ /\Alayout_/ || super
end