Class: Pith::Output
- Inherits:
-
Object
- Object
- Pith::Output
- Defined in:
- lib/pith/output.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#build ⇒ Object
Generate output for this template.
- #delete ⇒ Object
- #file ⇒ Object
-
#initialize(input, path) ⇒ Output
constructor
A new instance of Output.
- #invalidate ⇒ Object
- #project ⇒ Object
- #record_dependency_on(*inputs) ⇒ Object
Constructor Details
#initialize(input, path) ⇒ Output
Returns a new instance of Output.
13 14 15 16 |
# File 'lib/pith/output.rb', line 13 def initialize(input, path) @input = input @path = path end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
19 20 21 |
# File 'lib/pith/output.rb', line 19 def error @error end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
18 19 20 |
# File 'lib/pith/output.rb', line 18 def input @input end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/pith/output.rb', line 20 def path @path end |
Class Method Details
.for(input, path) ⇒ Object
9 10 11 |
# File 'lib/pith/output.rb', line 9 def self.for(input, path) new(input, path) end |
Instance Method Details
#build ⇒ Object
Generate output for this template
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pith/output.rb', line 32 def build return false if @generated logger.info("--> #{path}") @dependencies = Set.new file.parent.mkpath if input.template? evaluate_template else copy_resource end @generated = true end |
#delete ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/pith/output.rb', line 52 def delete invalidate if file.exist? logger.info("--X #{path}") FileUtils.rm_f(file) end end |
#file ⇒ Object
26 27 28 |
# File 'lib/pith/output.rb', line 26 def file @file ||= project.output_dir + path end |
#invalidate ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/pith/output.rb', line 60 def invalidate if @generated @dependencies.each do |d| d.remove_observer(self) end @dependencies = nil @generated = nil end end |
#project ⇒ Object
22 23 24 |
# File 'lib/pith/output.rb', line 22 def project input.project end |
#record_dependency_on(*inputs) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/pith/output.rb', line 45 def record_dependency_on(*inputs) inputs.each do |input| @dependencies << input input.add_observer(self, :invalidate) end end |