Class: Hardstatus

Inherits:
Object
  • Object
show all
Defined in:
lib/hardstatus/controller.rb,
lib/hardstatus.rb

Overview

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                  Version 2, December 2004

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

++

Defined Under Namespace

Classes: Controller

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHardstatus

Returns a new instance of Hardstatus.



24
25
26
27
28
29
30
# File 'lib/hardstatus.rb', line 24

def initialize
  @backticks = {}
  @controller = File.expand_path('~/.hardstatus.ctl')

  @left  = ""
  @right = ""
end

Instance Attribute Details

#left(template) ⇒ Object (readonly)

Returns the value of attribute left.



22
23
24
# File 'lib/hardstatus.rb', line 22

def left
  @left
end

#right(template) ⇒ Object (readonly)

Returns the value of attribute right.



22
23
24
# File 'lib/hardstatus.rb', line 22

def right
  @right
end

Class Method Details

.load(path) ⇒ Object



18
19
20
# File 'lib/hardstatus.rb', line 18

def self.load (path)
  Hardstatus.new.load(path)
end

Instance Method Details

#backtick(name, options = {}, &block) ⇒ Object



82
83
84
# File 'lib/hardstatus.rb', line 82

def backtick (name, options = {}, &block)
  @backticks[name] = Thread.every(options[:every] || 1, &block)
end

#controller(path) ⇒ Object



70
71
72
# File 'lib/hardstatus.rb', line 70

def controller (path)
  @controller = path
end

#load(path = nil, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/hardstatus.rb', line 32

def load (path = nil, &block)
  if path
    instance_eval File.read(File.expand_path(path)), path, 1
  else
    instance_exec(&block)
  end

  self
end

#render(side) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/hardstatus.rb', line 86

def render (side)
  instance_variable_get(:"@#{side}").gsub(/\#{.*?}/) { |m|
    if backtick = @backticks[m.match(/\#{(.*?)}/)[1].to_sym]
      backtick.value!.to_s
    end
  }
end

#startObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hardstatus.rb', line 42

def start
  return if started?

  @started = true

  File.umask(0).tap {|old|
    begin
      @signature = EM.start_server(@controller, Controller, self)
    ensure
      File.umask(old)
    end
  }
end

#started?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/hardstatus.rb', line 56

def started?
  @started
end

#stopObject



60
61
62
63
64
65
66
67
68
# File 'lib/hardstatus.rb', line 60

def stop
  return unless started?

  if @signature
    EM.stop_server @signature
  end

  @started = false
end