Class: Pith::Project
- Inherits:
-
Object
- Object
- Pith::Project
- Defined in:
- lib/pith/project.rb,
lib/pith/plugins/publication/project.rb
Instance Attribute Summary collapse
-
#config_provider ⇒ Object
readonly
Returns the value of attribute config_provider.
-
#input_dir ⇒ Object
readonly
Returns the value of attribute input_dir.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
Instance Method Summary collapse
-
#build ⇒ Object
Public: build the project, generating output files.
- #config ⇒ Object
-
#has_errors? ⇒ Boolean
Public: check for errors.
-
#initialize(input_dir, output_dir = nil, attributes = {}) ⇒ Project
constructor
A new instance of Project.
-
#input(path) ⇒ Object
Public: find an input.
-
#inputs ⇒ Object
Public: get inputs.
- #last_built_at ⇒ Object
-
#listen_for_changes ⇒ Object
Public: start a Thread to automatically sync when inputs change.
-
#output(path) ⇒ Object
Public: find an output.
-
#outputs ⇒ Object
Public: get outputs.
-
#published_inputs ⇒ Object
Return all the published inputs, in order of publication.
-
#sync ⇒ Object
Public: re-sync with the file-system.
Constructor Details
#initialize(input_dir, output_dir = nil, attributes = {}) ⇒ Project
Returns a new instance of Project.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pith/project.rb', line 15 def initialize(input_dir, output_dir = nil, attributes = {}) @input_dir = Pathname(input_dir) @output_dir = output_dir ? Pathname(output_dir) : (@input_dir + "_out") @logger = Logger.new(nil) attributes.each do |k,v| send("#{k}=", v) end @input_map = {} @output_map = {} @mtimes ||= {} @config_provider ||= Pith::ConfigProvider.new(self) @mutex = Mutex.new end |
Instance Attribute Details
#config_provider ⇒ Object (readonly)
Returns the value of attribute config_provider.
109 110 111 |
# File 'lib/pith/project.rb', line 109 def config_provider @config_provider end |
#input_dir ⇒ Object (readonly)
Returns the value of attribute input_dir.
29 30 31 |
# File 'lib/pith/project.rb', line 29 def input_dir @input_dir end |
#logger ⇒ Object
Returns the value of attribute logger.
108 109 110 |
# File 'lib/pith/project.rb', line 108 def logger @logger end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
30 31 32 |
# File 'lib/pith/project.rb', line 30 def output_dir @output_dir end |
Instance Method Details
#build ⇒ Object
Public: build the project, generating output files.
72 73 74 75 76 77 |
# File 'lib/pith/project.rb', line 72 def build sync output_dir.mkpath outputs.each(&:build) output_dir.touch end |
#config ⇒ Object
111 112 113 |
# File 'lib/pith/project.rb', line 111 def config config_provider.config end |
#has_errors? ⇒ Boolean
Public: check for errors.
Returns true if any errors were encountered during the last build.
100 101 102 |
# File 'lib/pith/project.rb', line 100 def has_errors? outputs.any?(&:error) end |
#input(path) ⇒ Object
Public: find an input.
path - an path relative to input_dir
Returns the first input whose path matches. Returns nil if no match is found.
55 56 57 |
# File 'lib/pith/project.rb', line 55 def input(path) @input_map[Pathname(path)] end |
#inputs ⇒ Object
Public: get inputs
Returns Pith::Input objects representing the files in the input_dir.
36 37 38 |
# File 'lib/pith/project.rb', line 36 def inputs @input_map.values end |
#last_built_at ⇒ Object
104 105 106 |
# File 'lib/pith/project.rb', line 104 def last_built_at output_dir.mtime end |
#listen_for_changes ⇒ Object
Public: start a Thread to automatically sync when inputs change.
91 92 93 94 95 |
# File 'lib/pith/project.rb', line 91 def listen_for_changes Listen.to(input_dir.to_s) do sync end.start end |
#output(path) ⇒ Object
Public: find an output.
path - an path relative to output_dir
Returns the first output whose path matches. Returns nil if no match is found.
66 67 68 |
# File 'lib/pith/project.rb', line 66 def output(path) @output_map[Pathname(path)] end |
#outputs ⇒ Object
Public: get outputs
Returns Pith::Output objects representing the files in the output_dir.
44 45 46 |
# File 'lib/pith/project.rb', line 44 def outputs inputs.map(&:output).compact end |
#published_inputs ⇒ Object
Return all the published inputs, in order of publication.
10 11 12 |
# File 'lib/pith/plugins/publication/project.rb', line 10 def published_inputs inputs.select { |i| i.published? }.sort_by { |i| i.published_at } end |
#sync ⇒ Object
Public: re-sync with the file-system.
81 82 83 84 85 86 87 |
# File 'lib/pith/project.rb', line 81 def sync @mutex.synchronize do config_provider.sync sync_input_files cleanup_output_files end end |