Class: SimpleStatsStore::Server
- Inherits:
-
Object
- Object
- SimpleStatsStore::Server
- Defined in:
- lib/simple_stats_store/server.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Server
constructor
A new instance of Server.
- #run(&block) ⇒ Object
- #scan ⇒ Object
Constructor Details
#initialize(options) ⇒ Server
Returns a new instance of Server.
3 4 5 6 7 |
# File 'lib/simple_stats_store/server.rb', line 3 def initialize() @data_dump = [:data_dump] @models = [:models] @name = [:name] || $0 end |
Instance Method Details
#run(&block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/simple_stats_store/server.rb', line 28 def run(&block) Process.fork do $0 = @name loop do self.scan yield if block_given? sleep 0.1 end end end |
#scan ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_stats_store/server.rb', line 9 def scan @data_dump.each do |stats| lines = stats.split("\n") if lines.shift != '---' or lines.pop != '---' puts "Corrupt statistics" return false end model = lines.shift.strip data = {} lines.each do |l| k, v = l.split(/:/, 2) data[k.strip.to_sym] = v.strip end @models[model.to_sym].create(data) end end |