Class: Blogdoor::Watcher
- Inherits:
-
Object
- Object
- Blogdoor::Watcher
- Extended by:
- Forwardable
- Defined in:
- lib/blogdoor/watcher.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
Returns the value of attribute builder.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Watcher
constructor
A new instance of Watcher.
- #start ⇒ Object
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
#builder ⇒ Object
Returns the value of attribute builder.
9 10 11 |
# File 'lib/blogdoor/watcher.rb', line 9 def builder @builder end |
Instance Method Details
#start ⇒ Object
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 |