Class: GryphonNest::Nest
- Inherits:
-
Object
- Object
- GryphonNest::Nest
- Defined in:
- lib/gryphon_nest.rb
Instance Method Summary collapse
- #build ⇒ Object
- #clean ⇒ Object
-
#initialize(compress, force) ⇒ Nest
constructor
A new instance of Nest.
- #serve(port) ⇒ Object
- #watch ⇒ Object
Constructor Details
#initialize(compress, force) ⇒ Nest
Returns a new instance of Nest.
26 27 28 29 30 31 32 |
# File 'lib/gryphon_nest.rb', line 26 def initialize(compress, force) @processors = Processors.create @logger = Logging.create @force = force @compressors = compress ? Compressors.create : [] @modifications = 0 end |
Instance Method Details
#build ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gryphon_nest.rb', line 35 def build unless Dir.exist?(CONTENT_DIR) raise Errors::NotFoundError, "Content directory doesn't exist in the current directory" end Dir.mkdir(BUILD_DIR) unless Dir.exist?(BUILD_DIR) existing_files = glob(BUILD_DIR, '{!.gz,!.br}') content_files = glob(CONTENT_DIR) processed_files = content_files.collect { |src| process_file(src) } files_to_delete = existing_files.difference(processed_files) files_to_delete.each { |file| delete_file(file) } @logger.info('No changes detected') if @modifications.zero? && files_to_delete.empty? end |
#clean ⇒ Object
51 52 53 54 |
# File 'lib/gryphon_nest.rb', line 51 def clean FileUtils.remove_dir(BUILD_DIR, true) @logger.info('Removed build dir') end |
#serve(port) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/gryphon_nest.rb', line 71 def serve(port) @logger.info("Running local server on #{port}") server = WEBrick::HTTPServer.new(Port: port, DocumentRoot: BUILD_DIR) # Trap ctrl c so we don't get the horrible stack trace trap('INT') { server.shutdown } server.start end |
#watch ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gryphon_nest.rb', line 56 def watch @logger.info('Watching for content changes') # Bypass modification checks, we already know the files been changed @force = true only = [/^#{CONTENT_DIR}/, /^#{DATA_DIR}/, /^#{LAYOUT_FILE}$/] Listen.to('.', relative: true, only: only) do |modified, added, removed| modified.union(added).each { |file| process_changes(file) } removed.each { |file| process_changes(file, removal: true) } end.start end |