Class: Mooset::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/mooset/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_filenameObject

Returns the value of attribute config_filename.



5
6
7
# File 'lib/mooset/application.rb', line 5

def config_filename
  @config_filename
end

Class Method Details

.run(argv) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mooset/application.rb', line 43

def self.run(argv)
  s = self.new

  OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options]"
    opts.on("-c", "--config FILE", "Config file", s.method(:config_filename=))
    opts.parse!(argv)
  end

  s.read_config
  s.run!
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



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

def configure(&block)
  yield self
end

#connectionsObject



21
22
23
# File 'lib/mooset/application.rb', line 21

def connections
  @connection ||= []
end

#define(endpoint_name, factory, *args) ⇒ Object



7
8
9
10
11
# File 'lib/mooset/application.rb', line 7

def define(endpoint_name, factory, *args)
  Mooset.define_singleton_method(endpoint_name) do
    Mooset::Endpoints::Endpoint.create(factory, endpoint_name, *args)
  end
end

#instancesObject



13
14
15
# File 'lib/mooset/application.rb', line 13

def instances
  @instances ||= {}
end

#read_configObject



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

def read_config
  instance_eval File.read(config_filename), config_filename
end

#run!Object



25
26
27
28
29
30
31
32
33
# File 'lib/mooset/application.rb', line 25

def run!
  connections.each do |event|
    from = instances[event[:from]]
    to = instances[event[:to]]
    opts = event[:opts]

    Mooset::SynchronizeUsers.call(from, to, opts)
  end
end

#synchronize_users(from:, to:, **opts) ⇒ Object



17
18
19
# File 'lib/mooset/application.rb', line 17

def synchronize_users(from:, to:, **opts)
  connections << { from: from, to: to, opts: opts }
end