Module: Magent

Defined in:
lib/magent/async.rb,
lib/magent.rb,
lib/magent/push.rb,
lib/magent/actor.rb,
lib/magent/utils.rb,
lib/magent/failure.rb,
lib/magent/processor.rb,
lib/magent/actor_channel.rb,
lib/magent/async_channel.rb,
lib/magent/generic_channel.rb,
lib/magent/web_socket_server.rb,
lib/magent/web_socket_channel.rb

Overview

Example

class Processor
  include Magent::Async
  [..snip..]

  def process
    puts "Processing #{@params}"
  end
end

async call:
    Processor.find(id).async(:my_queue).process.commit!(priority)
chained methods:
    Processor.async(:my_queue, true).find(1).process.commit!(priority)

Defined Under Namespace

Modules: Actor, Async, Failure, Utils Classes: ActorChannel, AsyncChannel, GenericChannel, Processor, WebSocketChannel, WebSocketServer

Constant Summary collapse

@@database_name =
"magent"
@@config =
{
  "host" => "0.0.0.0",
  "port" => 27017
}

Class Method Summary collapse

Class Method Details

.auth(username, passwd) ⇒ Object



91
92
93
94
# File 'lib/magent.rb', line 91

def self.auth(username, passwd)
  @@config['username'] = username
  @@config['password'] = passwd
end

.channel(name) ⇒ Object



6
7
8
# File 'lib/magent/push.rb', line 6

def self.channel(name)
  self.channels[name] ||= ActorChannel.new(name)
end

.channelsObject



10
11
12
# File 'lib/magent/push.rb', line 10

def self.channels
  @channels ||= {}
end

.configObject



56
57
58
# File 'lib/magent.rb', line 56

def self.config
  @@config
end

.config=(config) ⇒ Object



60
61
62
# File 'lib/magent.rb', line 60

def self.config=(config)
  @@config = config
end

.connect(environment, options = {}) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/magent.rb', line 64

def self.connect(environment, options={})
  raise 'Set config before connecting. Magent.config = {...}' if config.blank?

  env = config_for_environment(environment)
  Magent.connection = Mongo::Connection.new(env['host'], env['port'], options)
  Magent.database = env['database']
  Magent.database.authenticate(env['username'], env['password']) if env['username'] && env['password']
end

.connectionObject



35
36
37
# File 'lib/magent.rb', line 35

def self.connection
  @@connection ||= Mongo::Connection.new
end

.connection=(new_connection) ⇒ Object



43
44
45
# File 'lib/magent.rb', line 43

def self.connection=(new_connection)
  @@connection = new_connection
end

.current_actorObject



75
76
77
# File 'lib/magent/actor.rb', line 75

def self.current_actor
  @current_actor
end

.current_channelObject



79
80
81
# File 'lib/magent/actor.rb', line 79

def self.current_channel
  self.current_actor.channel
end

.databaseObject



52
53
54
# File 'lib/magent.rb', line 52

def self.database
  @@database ||= Magent.connection.db(@@database_name)
end

.database=(name) ⇒ Object



47
48
49
50
# File 'lib/magent.rb', line 47

def self.database=(name)
  @@database = nil
  @@database_name = name
end

.db_name=(db_name) ⇒ Object



87
88
89
# File 'lib/magent.rb', line 87

def self.db_name=(db_name)
  @@database_name = db_name
end

.host=(host) ⇒ Object

deprecated



79
80
81
# File 'lib/magent.rb', line 79

def self.host=(host)
  @@config['host'] = host
end

.loggerObject



39
40
41
# File 'lib/magent.rb', line 39

def self.logger
  connection.logger
end

.port=(port) ⇒ Object



83
84
85
# File 'lib/magent.rb', line 83

def self.port=(port)
  @@config['port'] = port
end

.push(channel_name, method, *args) ⇒ Object



2
3
4
# File 'lib/magent/push.rb', line 2

def self.push(channel_name, method, *args)
  self.channel(channel_name.to_s).push(method, args)
end

.register(actor) ⇒ Object

Actor



71
72
73
# File 'lib/magent/actor.rb', line 71

def self.register(actor)
  @current_actor = actor
end

.setup(config, environment = nil, options = {}) ⇒ Object



73
74
75
76
# File 'lib/magent.rb', line 73

def self.setup(config, environment = nil, options = {})
  self.config = config
  connect(environment, options)
end