Module: Goat::StateSrvClient

Defined in:
lib/goat/state-srv.rb

Class Method Summary collapse

Class Method Details

.component_updated(txn, pgid, update) ⇒ Object



35
36
37
# File 'lib/goat/state-srv.rb', line 35

def self.component_updated(txn, pgid, update)
  components_updated(txn, pgid, [update])
end

.components_updated(txn, pgid, updates) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/goat/state-srv.rb', line 39

def self.components_updated(txn, pgid, updates)
  send_message('components_updated',
    'txn' => txn,
    'pgid' => pgid,
    'updates' => updates.map(&:to_hash)
  )
end

.configure(opts = {}) ⇒ Object



3
4
5
6
# File 'lib/goat/state-srv.rb', line 3

def self.configure(opts={})
  @host = opts[:host]
  @port = opts[:port]
end

.fetch_component(id) ⇒ Object



30
31
32
33
# File 'lib/goat/state-srv.rb', line 30

def self.fetch_component(id)
  resp = send_message('fetch_component', {'id' => id}, true)
  ComponentSkeleton.from_hash(JSON.load(resp)['response'])
end

.live_components(cls, spec) ⇒ Object



25
26
27
28
# File 'lib/goat/state-srv.rb', line 25

def self.live_components(cls, spec)
  resp = send_message('live_components', {'class' => cls, 'spec' => spec}, true)
  JSON.load(resp)['response'].map{|h| ComponentSkeleton.from_hash(h)}
end

.register_page(pgid, user, cs) ⇒ Object



21
22
23
# File 'lib/goat/state-srv.rb', line 21

def self.register_page(pgid, user, cs)
  send_message('register_page', 'pgid' => pgid, 'user' => user, 'components' => cs.map(&:to_hash))
end

.scheduleObject



8
9
10
11
12
13
14
15
# File 'lib/goat/state-srv.rb', line 8

def self.schedule
  EM.next_tick {
    StateSrvConnection.connect(
      @host || '127.0.0.1',
      @port || 8011
    )
  }
end

.send_message(type, m, sync = false) ⇒ Object



17
18
19
# File 'lib/goat/state-srv.rb', line 17

def self.send_message(type, m, sync=false)
  StateSrvConnection.send_message(type, m, sync)
end