Class: SynchronizeUsers::App

Inherits:
Object
  • Object
show all
Defined in:
lib/synchronize-users/app.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/synchronize-users/app.rb', line 3

def config
  @config
end

#config_filenameObject

Returns the value of attribute config_filename.



3
4
5
# File 'lib/synchronize-users/app.rb', line 3

def config_filename
  @config_filename
end

#logfileObject

Returns the value of attribute logfile.



3
4
5
# File 'lib/synchronize-users/app.rb', line 3

def logfile
  @logfile
end

Class Method Details

.run(argv) ⇒ Object



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

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.parse!(argv)
  end

  LSpace[:logger] = s.logger

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

Instance Method Details

#loggerObject



36
37
38
39
40
# File 'lib/synchronize-users/app.rb', line 36

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

#read_configObject



10
11
12
# File 'lib/synchronize-users/app.rb', line 10

def read_config
  @config = SynchronizeUsers.load_config(config_filename)
end

#run!Object



5
6
7
8
# File 'lib/synchronize-users/app.rb', line 5

def run!
  app = SynchronizeUsers::Sync.new(@config)
  app.run!
end