Class: Syncro::App

Inherits:
Object
  • Object
show all
Defined in:
lib/syncro/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ App

Returns a new instance of App.



5
6
7
# File 'lib/syncro/app.rb', line 5

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/syncro/app.rb', line 3

def client
  @client
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/syncro/app.rb', line 3

def message
  @message
end

Instance Method Details

#add_scribe(scribe, &block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/syncro/app.rb', line 37

def add_scribe(scribe, &block)
  invoke(
    :add_scribe, 
    :scribe => scribe, 
    &block
  )
end

#call(message) ⇒ Object



9
10
11
12
13
# File 'lib/syncro/app.rb', line 9

def call(message)
  @message = message
  method   = "invoke_#{message.type}"
  send(method) if respond_to?(method)
end

#syncObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/syncro/app.rb', line 15

def sync
  invoke(:sync, :from => client.last_scribe_id) do |resp|
    scribes = resp.map {|s| 
      scribe = Scriber::Scribe.new(s)
      scribe.from_client = client.to_s
      scribe
    }
    allowed_scribes = scribes.select {|s| 
      allowed_klasses.include?(s.klass) 
    }
    allowed_scribes.each {|s| s.play }
    
    if scribes.any?
      client.update_attribute(
        :last_scribe_id, 
        scribes.last.id
      )
    end
    yield if block_given?
  end
end