Class: Pith::Project
- Inherits:
-
Object
- Object
- Pith::Project
- Defined in:
- lib/pith/project.rb,
lib/pith/plugins/publication/project.rb
Instance Attribute Summary collapse
-
#input_dir ⇒ Object
readonly
Returns the value of attribute input_dir.
- #logger ⇒ Object readonly
-
#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
- #config_provider ⇒ 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
-
#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.
- #sync_every(period) ⇒ Object
Constructor Details
#initialize(input_dir, output_dir = nil, attributes = {}) ⇒ Project
Returns a new instance of Project.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pith/project.rb', line 13 def initialize(input_dir, output_dir = nil, attributes = {}) @input_dir = Pathname(input_dir) @output_dir = output_dir ? Pathname(output_dir) : (@input_dir + "_out") @input_map = {} @output_map = {} attributes.each do |k,v| send("#{k}=", v) end FileUtils.rm_rf(output_dir.to_s) end |
Instance Attribute Details
#input_dir ⇒ Object (readonly)
Returns the value of attribute input_dir.
24 25 26 |
# File 'lib/pith/project.rb', line 24 def input_dir @input_dir end |
#logger ⇒ Object
101 102 103 |
# File 'lib/pith/project.rb', line 101 def logger @logger ||= Logger.new(nil) end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
25 26 27 |
# File 'lib/pith/project.rb', line 25 def output_dir @output_dir end |
Instance Method Details
#build ⇒ Object
Public: build the project, generating output files.
67 68 69 70 71 72 |
# File 'lib/pith/project.rb', line 67 def build sync output_dir.mkpath outputs.each(&:build) output_dir.touch end |
#config ⇒ Object
109 110 111 |
# File 'lib/pith/project.rb', line 109 def config config_provider.config end |
#config_provider ⇒ Object
105 106 107 |
# File 'lib/pith/project.rb', line 105 def config_provider @config_provider ||= Pith::ConfigProvider.new(self) end |
#has_errors? ⇒ Boolean
Public: check for errors.
Returns true if any errors were encountered during the last build.
93 94 95 |
# File 'lib/pith/project.rb', line 93 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.
50 51 52 |
# File 'lib/pith/project.rb', line 50 def input(path) @input_map[Pathname(path)] end |
#inputs ⇒ Object
Public: get inputs
Returns Pith::Input objects representing the files in the input_dir.
31 32 33 |
# File 'lib/pith/project.rb', line 31 def inputs @input_map.values end |
#last_built_at ⇒ Object
97 98 99 |
# File 'lib/pith/project.rb', line 97 def last_built_at output_dir.mtime 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.
61 62 63 |
# File 'lib/pith/project.rb', line 61 def output(path) @output_map[Pathname(path)] end |
#outputs ⇒ Object
Public: get outputs
Returns Pith::Output objects representing the files in the output_dir.
39 40 41 |
# File 'lib/pith/project.rb', line 39 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.
76 77 78 79 |
# File 'lib/pith/project.rb', line 76 def sync config_provider.sync sync_input_files end |
#sync_every(period) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/pith/project.rb', line 81 def sync_every(period) @next_sync ||= 0 now = Time.now.to_i if now >= @next_sync sync @next_sync = now + period end end |