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.



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

def config_filename
  @config_filename
end

#interactiveObject

Returns the value of attribute interactive.



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

def interactive
  @interactive
end

#logfileObject

Returns the value of attribute logfile.



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

def logfile
  @logfile
end

Class Method Details

.run(argv) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mooset/application.rb', line 51

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

  OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options]"
    opts.on("-f", "--logfile FILE", "Logfile", s.method(:logfile=))
    opts.on("-v", "--verbose", "Verbose") do |x|
      s.logger.level = ::Logger::DEBUG
    end

    opts.on("-c", "--config FILE", "Config file", s.method(:config_filename=))
    opts.on("-i", "--interactive", "Run in interactive mode", s.method(:interactive=))
    opts.parse!(argv)
  end

  LSpace[:logger] = s.logger

  if s.config_filename
    s.read_config
    s.run! unless s.interactive
  end

  s.start_irb if s.interactive
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



47
48
49
# File 'lib/mooset/application.rb', line 47

def configure(&block)
  yield self
end

#define(endpoint_name, factory, opts = {}) ⇒ Object



9
10
11
12
13
# File 'lib/mooset/application.rb', line 9

def define(endpoint_name, factory, opts = {})
  opts[:endpoint_name] = endpoint_name

  endpoints[endpoint_name] = Mooset::Endpoints::Endpoint.create(factory, opts)
end

#endpointsObject



15
16
17
# File 'lib/mooset/application.rb', line 15

def endpoints
  @endpoints ||= {}
end

#instancesObject



19
20
21
# File 'lib/mooset/application.rb', line 19

def instances
  @instances ||= {}
end

#loggerObject



76
77
78
79
80
# File 'lib/mooset/application.rb', line 76

def logger
  @logger ||= ::Logger.new(logfile || STDOUT).tap do |l|
    l.level = ::Logger::INFO
  end
end

#operationsObject



27
28
29
# File 'lib/mooset/application.rb', line 27

def operations
  @operations ||= []
end

#read_configObject



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

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

#run!Object



31
32
33
34
35
# File 'lib/mooset/application.rb', line 31

def run!
  operations.each do |operation|
    operation.call
  end
end

#start_irbObject



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

def start_irb
  $app = self

  IRB.start
end

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



23
24
25
# File 'lib/mooset/application.rb', line 23

def synchronize_group(from:, to:, **opts)
  operations << Mooset::SynchronizeGroup.new(endpoints[from], endpoints[to], opts)
end