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



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/uh/wm/action_handler.rb', line 44

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
# File 'lib/uh/wm/action_handler.rb', line 24

def execute(command)
  log "Spawn `#{command}`"
  pid = spawn command, pgroup: true
  Process.detach pid
rescue Errno::ENOENT => e
  log_error "Spawn: #{e}"
end

#log_clientsObject



36
37
38
# File 'lib/uh/wm/action_handler.rb', line 36

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

#log_layoutObject



32
33
34
# File 'lib/uh/wm/action_handler.rb', line 32

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

#log_separatorObject



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

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)


58
59
60
# File 'lib/uh/wm/action_handler.rb', line 58

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