Class: Listen::Listener::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/listen/listener/config.rb

Constant Summary collapse

DEFAULTS =
{
  # Listener options
  debug: false, # TODO: is this broken?
  wait_for_delay: nil, # NOTE: should be provided by adapter if possible
  relative: false,

  # Backend selecting options
  force_polling: false,
  polling_fallback_message: nil
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Config

Returns a new instance of Config.



17
18
19
20
21
22
# File 'lib/listen/listener/config.rb', line 17

def initialize(opts)
  @options = DEFAULTS.merge(opts)
  @relative = @options[:relative]
  @min_delay_between_events = @options[:wait_for_delay]
  @silencer_rules = @options # silencer will extract what it needs
end

Instance Attribute Details

#min_delay_between_eventsObject (readonly)

Returns the value of attribute min_delay_between_events.



28
29
30
# File 'lib/listen/listener/config.rb', line 28

def min_delay_between_events
  @min_delay_between_events
end

#silencer_rulesObject (readonly)

Returns the value of attribute silencer_rules.



28
29
30
# File 'lib/listen/listener/config.rb', line 28

def silencer_rules
  @silencer_rules
end

Instance Method Details

#adapter_instance_options(klass) ⇒ Object



30
31
32
33
# File 'lib/listen/listener/config.rb', line 30

def adapter_instance_options(klass)
  valid_keys = klass.const_get('DEFAULTS').keys
  Hash[@options.select { |key, _| valid_keys.include?(key) }]
end

#adapter_select_optionsObject



35
36
37
38
# File 'lib/listen/listener/config.rb', line 35

def adapter_select_options
  valid_keys = %w[force_polling polling_fallback_message].map(&:to_sym)
  Hash[@options.select { |key, _| valid_keys.include?(key) }]
end

#relative?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/listen/listener/config.rb', line 24

def relative?
  @relative
end