Class: FireflyServer::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/firefly_server/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Configuration

Returns a new instance of Configuration.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/firefly_server/configuration.rb', line 19

def initialize(params = {})
  # defaults
  self.restart_attempt_throttle_threshold = 3
  self.restart_attempt_throttle_sleep = 3
  self.exit_signals = %w[ SIGINT ]
  # watcher defaults
  self.watch_paths = []
  self.ignore_paths = []
  self.on_change_callbacks = []
  self.on_start_callbacks = []
  # override defaults
  params.each do |key, value|
    send("#{key}=", value)
  end
end

Instance Method Details

#on_change(&block) ⇒ Object



46
47
48
49
# File 'lib/firefly_server/configuration.rb', line 46

def on_change(&block)
  on_change_callbacks << block if block
  self
end

#on_start(&block) ⇒ Object



51
52
53
54
# File 'lib/firefly_server/configuration.rb', line 51

def on_start(&block)
  on_start_callbacks << block if block
  self
end

#validate!Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/firefly_server/configuration.rb', line 56

def validate!
  # validate require options set
  %w[ start_server stop_server pid_file ].each do |attribute|
    if !send(attribute)
      raise(ArgumentError, "#{attribute} option must be provided")
    end
  end
  if watch_paths.empty?
    raise(ArgumentError, "watch_paths option must be provided")
  end
  self
end