Class: Listen::Listener

Inherits:
Object show all
Includes:
FSM
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener/config.rb

Defined Under Namespace

Classes: Config

Instance Attribute Summary

Attributes included from FSM

#state

Instance Method Summary collapse

Methods included from FSM

included, #initialize_fsm, #wait_for_state

Constructor Details

#initialize(*dirs) {|modified, added, removed| ... } ⇒ Listener

Initializes the directories listener.

rubocop:disable Metrics/MethodLength

Parameters:

  • directory (String)

    the directories to listen to

  • options (Hash)

    the listen options (see Listen::Listener::Options)

Yields:

  • (modified, added, removed)

    the changed files

Yield Parameters:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 37

def initialize(*dirs, &block)
  options = dirs.last.is_a?(Hash) ? dirs.pop : {}

  @config = Config.new(options)

  eq_config = Event::Queue::Config.new(@config.relative?)
  queue = Event::Queue.new(eq_config)

  silencer = Silencer.new
  rules = @config.silencer_rules
  @silencer_controller = Silencer::Controller.new(silencer, rules)

  @backend = Backend.new(dirs, queue, silencer, @config)

  optimizer_config = QueueOptimizer::Config.new(@backend, silencer)

  pconfig = Event::Config.new(
    self,
    queue,
    QueueOptimizer.new(optimizer_config),
    @backend.min_delay_between_events,
    &block)

  @processor = Event::Loop.new(pconfig)

  initialize_fsm
end

Instance Method Details

#ignore(regexps) ⇒ Object



124
125
126
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 124

def ignore(regexps)
  @silencer_controller.append_ignores(regexps)
end

#ignore!(regexps) ⇒ Object



128
129
130
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 128

def ignore!(regexps)
  @silencer_controller.replace_with_bang_ignores(regexps)
end

#only(regexps) ⇒ Object



132
133
134
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 132

def only(regexps)
  @silencer_controller.replace_with_only(regexps)
end

#pauseObject

Stops invoking callbacks (messages pile up)



107
108
109
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 107

def pause
  transition :paused
end

#paused?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 116

def paused?
  state == :paused
end

#processing?Boolean

processing means callbacks are called

Returns:

  • (Boolean)


112
113
114
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 112

def processing?
  state == :processing_events
end

#startObject

Starts processing events and starts adapters or resumes invoking callbacks if paused



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 89

def start
  case state
  when :initializing
    transition :backend_started
    transition :processing_events
  when :paused
    transition :processing_events
  else
    raise ArgumentError, "cannot start from state #{state.inspect}"
  end
end

#stopObject

Stops both listening for events and processing them



102
103
104
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 102

def stop
  transition :stopped
end

#stopped?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/listener.rb', line 120

def stopped?
  state == :stopped
end