Class: Computron::Simulation
- Inherits:
-
Object
- Object
- Computron::Simulation
- Defined in:
- lib/computron/simulation.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #default_host(host = nil) ⇒ Object
- #every(interval, opts = {}, &block) ⇒ Object
- #halt! ⇒ Object
-
#initialize(&block) ⇒ Simulation
constructor
A new instance of Simulation.
- #run! ⇒ Object
-
#url(path) ⇒ Object
Deal with paths and URLs.
Constructor Details
#initialize(&block) ⇒ Simulation
Returns a new instance of Simulation.
5 6 7 8 |
# File 'lib/computron/simulation.rb', line 5 def initialize(&block) @client = Client.new @simulation = Proc.new { instance_eval(&block) } end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/computron/simulation.rb', line 3 def client @client end |
Instance Method Details
#default_host(host = nil) ⇒ Object
18 19 20 |
# File 'lib/computron/simulation.rb', line 18 def default_host(host=nil) host ? @default_host = host : @default_host end |
#every(interval, opts = {}, &block) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/computron/simulation.rb', line 22 def every(interval, opts={}, &block) timer = EventMachine::PeriodicTimer.new(0) do timer.interval = interval.respond_to?(:call) ? interval.call : interval block.call(timer) end end |
#halt! ⇒ Object
14 15 16 |
# File 'lib/computron/simulation.rb', line 14 def halt! EM::stop end |
#run! ⇒ Object
10 11 12 |
# File 'lib/computron/simulation.rb', line 10 def run! EM::run { @simulation.call } end |
#url(path) ⇒ Object
Deal with paths and URLs
38 39 40 41 42 43 |
# File 'lib/computron/simulation.rb', line 38 def url(path) url = String.new url.concat "http://#{default_host}" unless url =~ %r{^(\w+)://} if default_host url.concat path =~ /^\// ? path : "/#{path}" # Deal with leading /\ url end |