Module: Robin

Defined in:
lib/robin/rails.rb,
lib/robin.rb,
lib/robin-rails.rb,
lib/robin/rails/version.rb

Overview

require ‘robin’

Defined Under Namespace

Modules: Rails

Constant Summary collapse

@@faye_url =
'http://localhost:9292/faye'

Class Method Summary collapse

Class Method Details

.channel_for(record, event) ⇒ Object



22
23
24
# File 'lib/robin.rb', line 22

def channel_for(record, event)
  "/#{record.class.model_name.route_key}/#{event}"
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Robin)

    the object that the method was called on



8
9
10
# File 'lib/robin.rb', line 8

def configure
  yield self
end

.publish(record, event, data) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/robin.rb', line 12

def publish record, event, data
  msg = {
    channel: channel_for(record, event),
    data: data
  }

  uri = URI.parse("http://localhost:9292/faye")
  Net::HTTP.post_form(uri, message: msg.to_json)
end