Class: Flok::Service
- Inherits:
-
Object
- Object
- Flok::Service
- Defined in:
- lib/flok/services_compiler.rb
Instance Attribute Summary collapse
-
#_global ⇒ Object
Returns the value of attribute _global.
-
#_on_connect ⇒ Object
Returns the value of attribute _on_connect.
-
#_on_disconnect ⇒ Object
Returns the value of attribute _on_disconnect.
-
#_on_sleep ⇒ Object
Returns the value of attribute _on_sleep.
-
#_on_wakeup ⇒ Object
Returns the value of attribute _on_wakeup.
-
#event_handlers ⇒ Object
Returns the value of attribute event_handlers.
-
#every_handlers ⇒ Object
Returns the value of attribute every_handlers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #every(seconds, str) ⇒ Object
- #get_on_init ⇒ Object
- #get_on_request ⇒ Object
- #global(str) ⇒ Object
-
#initialize(name, options) ⇒ Service
constructor
A new instance of Service.
- #macro(text) ⇒ Object
- #on(name, str) ⇒ Object
- #on_connect(str) ⇒ Object
- #on_disconnect(str) ⇒ Object
- #on_sleep(str) ⇒ Object
- #on_wakeup(str) ⇒ Object
- #type(str) ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Service
Returns a new instance of Service.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/flok/services_compiler.rb', line 89 def initialize name, @name = name @options = #These are the 'on' handlers @event_handlers = [] #These are for every 5.seconds @every_handlers = [] @debug = true if ENV["FLOK_ENV"] == "DEBUG" @release = true if ENV["FLOK_ENV"] == "RELEASE" end |
Instance Attribute Details
#_global ⇒ Object
Returns the value of attribute _global.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def _global @_global end |
#_on_connect ⇒ Object
Returns the value of attribute _on_connect.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def _on_connect @_on_connect end |
#_on_disconnect ⇒ Object
Returns the value of attribute _on_disconnect.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def _on_disconnect @_on_disconnect end |
#_on_sleep ⇒ Object
Returns the value of attribute _on_sleep.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def _on_sleep @_on_sleep end |
#_on_wakeup ⇒ Object
Returns the value of attribute _on_wakeup.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def _on_wakeup @_on_wakeup end |
#event_handlers ⇒ Object
Returns the value of attribute event_handlers.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def event_handlers @event_handlers end |
#every_handlers ⇒ Object
Returns the value of attribute every_handlers.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def every_handlers @every_handlers end |
#name ⇒ Object
Returns the value of attribute name.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
88 89 90 |
# File 'lib/flok/services_compiler.rb', line 88 def @options end |
Instance Method Details
#every(seconds, str) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/flok/services_compiler.rb', line 152 def every(seconds, str) @every_handlers << { :name => "#{seconds}_sec_#{SecureRandom.hex[0..6]}", :ticks => seconds*4, :str => macro(str) } end |
#get_on_init ⇒ Object
103 104 105 |
# File 'lib/flok/services_compiler.rb', line 103 def get_on_init return @on_init end |
#get_on_request ⇒ Object
107 108 109 |
# File 'lib/flok/services_compiler.rb', line 107 def get_on_request return @on_request end |
#global(str) ⇒ Object
111 112 113 114 115 |
# File 'lib/flok/services_compiler.rb', line 111 def global(str) render = ERB.new(str) str = render.result(binding) @_global = macro(str) end |
#macro(text) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/flok/services_compiler.rb', line 168 def macro text return Flok.macro_process(text) #out = StringIO.new #text.split("\n").each do |l| ##Request(vc_name, spot_name, context) macro #if l =~ /Request/ #l.strip! #l.gsub!(/Request\(/, "") #l.gsub! /\)$/, "" #l.gsub! /\);$/, "" #o = l.split(",").map{|e| e.strip} #service_name = o.shift.gsub(/"/, "") #info = o.shift.gsub(/"/, "") #event_name = o.shift.gsub(/"/, "") #out << %{ #} #else #out.puts l #end #end #return out.string end |
#on(name, str) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/flok/services_compiler.rb', line 142 def on(name, str) render = ERB.new(str) str = render.result(binding) @event_handlers << { :name => name, :str => macro(str) } end |
#on_connect(str) ⇒ Object
130 131 132 133 134 |
# File 'lib/flok/services_compiler.rb', line 130 def on_connect(str) render = ERB.new(str) str = render.result(binding) @_on_connect = macro(str) end |
#on_disconnect(str) ⇒ Object
136 137 138 139 140 |
# File 'lib/flok/services_compiler.rb', line 136 def on_disconnect(str) render = ERB.new(str) str = render.result(binding) @_on_disconnect = macro(str) end |
#on_sleep(str) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/flok/services_compiler.rb', line 123 def on_sleep(str) render = ERB.new(str) str = render.result(binding) @_on_sleep = macro(str) end |
#on_wakeup(str) ⇒ Object
117 118 119 120 121 |
# File 'lib/flok/services_compiler.rb', line 117 def on_wakeup(str) render = ERB.new(str) str = render.result(binding) @_on_wakeup = macro(str) end |
#type(str) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/flok/services_compiler.rb', line 160 def type str @_type = str.to_s unless ["daemon", "agent"].include? @_type raise "You gave a type for the service, #{@_type.inspect} but this wasn't a valid type of service. Should be \ either 'daemon' or 'agent'" end end |