Class: Pith::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/pith/output.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#errorObject (readonly)

Returns the value of attribute error.



19
20
21
# File 'lib/pith/output.rb', line 19

def error
  @error
end

#inputObject (readonly)

Returns the value of attribute input.



18
19
20
# File 'lib/pith/output.rb', line 18

def input
  @input
end

#pathObject (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

#buildObject

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

#deleteObject



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

#fileObject



26
27
28
# File 'lib/pith/output.rb', line 26

def file
  @file ||= project.output_dir + path
end

#invalidateObject



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

#projectObject



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