Class: Hardstatus
- Inherits:
-
Object
- Object
- Hardstatus
- 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
- You just DO WHAT THE FUCK YOU WANT TO. ++
Defined Under Namespace
Classes: Controller
Instance Attribute Summary collapse
-
#left(template) ⇒ Object
readonly
Returns the value of attribute left.
-
#right(template) ⇒ Object
readonly
Returns the value of attribute right.
Class Method Summary collapse
Instance Method Summary collapse
- #backtick(name, options = {}, &block) ⇒ Object
- #controller(path) ⇒ Object
-
#initialize ⇒ Hardstatus
constructor
A new instance of Hardstatus.
- #load(path = nil, &block) ⇒ Object
- #render(side) ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Hardstatus
Returns a new instance of Hardstatus.
24 25 26 27 28 29 30 |
# File 'lib/hardstatus.rb', line 24 def initialize @backticks = {} @controller = File.('~/.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, = {}, &block) @backticks[name] = Thread.every([: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.(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 |
#start ⇒ Object
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
56 57 58 |
# File 'lib/hardstatus.rb', line 56 def started? @started end |
#stop ⇒ Object
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 |