Class: Listen::Adapter::Base
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb
Constant Summary collapse
- DEFAULTS =
TODO: only used by tests
{}.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#configure ⇒ Object
TODO: it’s a separate method as a temporary workaround for tests rubocop:disable Metrics/MethodLength.
-
#initialize(config) ⇒ Base
constructor
A new instance of Base.
- #start ⇒ Object
-
#started? ⇒ Boolean
rubocop:enable Metrics/MethodLength.
- #stop ⇒ Object
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 16 def initialize(config) @started = false @config = config @configured = nil fail 'No directories to watch!' if config.directories.empty? defaults = self.class.const_get('DEFAULTS') @options = Listen::Options.new(config., defaults) rescue _log_exception 'adapter config failed: %s:%s called from: %s', caller raise end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 11 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 11 def @options end |
Class Method Details
.usable? ⇒ Boolean
123 124 125 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 123 def usable? const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os'] end |
Instance Method Details
#configure ⇒ Object
TODO: it’s a separate method as a temporary workaround for tests rubocop:disable Metrics/MethodLength
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 33 def configure if @configured Listen.logger.warn('Adapter already configured!') return end @configured = true @callbacks ||= {} config.directories.each do |dir| callback = @callbacks[dir] || lambda do |event| _process_event(dir, event) end @callbacks[dir] = callback _configure(dir, &callback) end @snapshots ||= {} # TODO: separate config per directory (some day maybe) change_config = Change::Config.new(config.queue, config.silencer) config.directories.each do |dir| record = Record.new(dir, config.silencer) snapshot = Change.new(change_config, record) @snapshots[dir] = snapshot end end |
#start ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 65 def start configure if started? Listen.logger.warn('Adapter already started!') return end @started = true @run_thread = Listen::Thread.new("run_thread") do @snapshots.each_value do |snapshot| _timed('Record.build()') { snapshot.record.build } end _run end end |
#started? ⇒ Boolean
rubocop:enable Metrics/MethodLength
61 62 63 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 61 def started? @started end |
#stop ⇒ Object
83 84 85 86 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter/base.rb', line 83 def stop _stop config.queue.close # this causes queue.pop to return `nil` to the front-end end |