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

def initialize
	@backticks = {}
	@controller = File.expand_path('~/.hardstatus.ctl')
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



79
80
81
# File 'lib/hardstatus.rb', line 79

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

#controller(path) ⇒ Object



67
68
69
# File 'lib/hardstatus.rb', line 67

def controller (path)
	@controller = path
end

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



29
30
31
32
33
34
35
36
37
# File 'lib/hardstatus.rb', line 29

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



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

def render (side)
	template = case side
	             when :left  then @left || ""
	             when :right then @right || ""
	           end

	template.gsub(/\#{.*?}/) { |m|
		@backticks[m.match(/\#{(.*?)}/)[1].to_sym].value!.to_s
	}
end

#startObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hardstatus.rb', line 39

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)


53
54
55
# File 'lib/hardstatus.rb', line 53

def started?
	@started
end

#stopObject



57
58
59
60
61
62
63
64
65
# File 'lib/hardstatus.rb', line 57

def stop
	return unless started?

	if @signature
		EM.stop_server @signature
	end

	@started = false
end