Class: Gryphon::Nest

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/gryphon.rb

Instance Method Summary collapse

Methods included from Logging

#log

Constructor Details

#initialize(processors, compressors, force) ⇒ Nest

Returns a new instance of Nest.

Parameters:

  • processors (Array<Object>)
  • compressors (Array<Object>)
  • force (Boolean)


29
30
31
32
33
34
# File 'lib/gryphon.rb', line 29

def initialize(processors, compressors, force)
  @processors = processors
  @compressors = compressors
  @force = force
  @modifications = 0
end

Instance Method Details

#buildObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gryphon.rb', line 37

def build
  unless Dir.exist?(CONTENT_DIR)
    raise Errors::NotFoundError, "Content directory doesn't exist in the current directory"
  end

  FileUtils.mkdir_p(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) }

  log('No changes detected') if @modifications.zero? && files_to_delete.empty?
end

#cleanObject



52
53
54
55
# File 'lib/gryphon.rb', line 52

def clean
  FileUtils.remove_dir(BUILD_DIR, true)
  log('Removed build dir')
end

#serve(port, monitor) ⇒ Object

Parameters:

  • port (Integer)
  • monitor (Boolean)


59
60
61
62
63
64
65
66
67
# File 'lib/gryphon.rb', line 59

def serve(port, monitor)
  watch if monitor

  log("Running local server on #{port}")
  server = WEBrick::HTTPServer.new(Port: port, DocumentRoot: BUILD_DIR, AccessLog: [])
  # Trap ctrl c so we don't get the horrible stack trace
  trap('INT') { server.shutdown }
  server.start
end