Class: Blogdoor::Watcher

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/blogdoor/watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Watcher

Returns a new instance of Watcher.



12
13
14
# File 'lib/blogdoor/watcher.rb', line 12

def initialize(args = {})
  @root_path = Pathname.new(args[:root_path] || ".")
end

Instance Attribute Details

#builderObject

Returns the value of attribute builder.



9
10
11
# File 'lib/blogdoor/watcher.rb', line 9

def builder
  @builder
end

Instance Method Details

#startObject



16
17
18
19
20
21
22
23
24
# File 'lib/blogdoor/watcher.rb', line 16

def start
  listener = Listen.to(@root_path.to_s, only: /\.md$/) do |modified, added|
    [modified, added].flatten.each do |file_path|
      build(Pathname.new(file_path))
    end
  end
  trap(:INT) { listener.stop }
  listener.start
end