Class: Mailman::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/mailman/cli.rb

Defined Under Namespace

Classes: ConfigNotDefined

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
# File 'lib/mailman/cli.rb', line 7

def initialize(options = {})
  @config_file = options[:config_file]
  @pid_file = options[:pid_file]
  @environment = options[:environment]
end

Instance Method Details

#load_configObject



23
24
25
26
27
28
29
# File 'lib/mailman/cli.rb', line 23

def load_config
  if @config_file
    require @config_file
  else
    raise ConfigNotDefined.new
  end
end

#record_pid_fileObject



31
32
33
34
35
36
37
# File 'lib/mailman/cli.rb', line 31

def record_pid_file
  if @pid_file
    File.open(@pid_file, 'w') do |f|
      f.puts Process.pid
    end
  end
end

#runObject



13
14
15
16
17
# File 'lib/mailman/cli.rb', line 13

def run
  set_environment
  record_pid_file
  load_config
end

#set_environmentObject



19
20
21
# File 'lib/mailman/cli.rb', line 19

def set_environment
  ENV['RACK_ENV'] = ENV['RAILS_ENV'] = @environment
end