Class: Smartgen::Watcher
- Inherits:
-
Object
- Object
- Smartgen::Watcher
- Defined in:
- lib/smartgen/watcher.rb
Overview
Watches for changes in configured files and regenerated them as they are changed.
Just pass the name of the resource to it and call #start. It will generate the files right away and it will keep watching for changes in those files. Every time a file is added, changed or removed, it will regenerate all files.
You can also pass a block when initializing to create and configure the resource.
For example:
watcher = Smartgen::Watcher.new :my_resource do |config|
config.src_files = ['docs/**/*']
config.output_folder = 'public_docs'
end
watcher.start
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#generate(*args) ⇒ Object
Generate files.
-
#initialize(name, &block) ⇒ Watcher
constructor
A new instance of Watcher.
-
#start ⇒ Object
Starts watching files for changes.
Constructor Details
#initialize(name, &block) ⇒ Watcher
Returns a new instance of Watcher.
25 26 27 28 |
# File 'lib/smartgen/watcher.rb', line 25 def initialize(name, &block) @name = name configure(&block) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/smartgen/watcher.rb', line 23 def name @name end |
Instance Method Details
#generate(*args) ⇒ Object
Generate files.
40 41 42 43 44 |
# File 'lib/smartgen/watcher.rb', line 40 def generate(*args) puts "Regenerating files, #{args.size} files have been added/changed/removed." Smartgen[@name].generate! puts "Files generated." end |
#start ⇒ Object
Starts watching files for changes.
31 32 33 34 35 36 37 |
# File 'lib/smartgen/watcher.rb', line 31 def start puts "Watching these files for changes #{glob}..." configure_directory_watcher setup_graceful_exit directory_watcher.start.join end |