Class: Litbuild::Blueprint
- Inherits:
-
Object
- Object
- Litbuild::Blueprint
show all
- Defined in:
- lib/litbuild/blueprint.rb
Overview
Blueprints are described in the ‘doc` directory.
tl;dr:
Blueprints are considered as “chunks” separated by blank lines. Each chunk can be either directives or narrative. Narrative is AsciiDoc and does not get parsed or transformed. Directives are basically a simplified version of YAML.
After parsing, the narrative is found in the ‘grafs` variables and directives are found in `directive` hashes.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(text:, parameters:, logfile_namer:, library:) ⇒ Blueprint
Returns a new instance of Blueprint.
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/litbuild/blueprint.rb', line 36
def initialize(text:, parameters:, logfile_namer:, library:)
parser = BlueprintParser.new(file_text: text, parameters: parameters)
@base_directives = parser.base_directives
@phase_directives = parser.phase_directives
@base_grafs = parser.base_grafs
@phase_grafs = parser.phase_grafs
@active_phase = @base_directives['default-phase']&.first
@logfile_namer = logfile_namer
@bp_library = library
end
|
Instance Attribute Details
#active_phase ⇒ Object
Returns the value of attribute active_phase.
30
31
32
|
# File 'lib/litbuild/blueprint.rb', line 30
def active_phase
@active_phase
end
|
#base_grafs ⇒ Object
Returns the value of attribute base_grafs.
30
31
32
|
# File 'lib/litbuild/blueprint.rb', line 30
def base_grafs
@base_grafs
end
|
#logfile_namer ⇒ Object
Returns the value of attribute logfile_namer.
30
31
32
|
# File 'lib/litbuild/blueprint.rb', line 30
def logfile_namer
@logfile_namer
end
|
Class Method Details
.descendants ⇒ Object
32
33
34
|
# File 'lib/litbuild/blueprint.rb', line 32
def self.descendants
ObjectSpace.each_object(Class).select { |c| c < self }
end
|
.directory_name ⇒ Object
This should simply be the name of the directory where blueprints of each specific type are expected to be found by Driver.
25
26
27
|
# File 'lib/litbuild/blueprint.rb', line 25
def self.directory_name
raise(SubclassResponsibility)
end
|
Instance Method Details
#[](directive) ⇒ Object
87
88
89
|
# File 'lib/litbuild/blueprint.rb', line 87
def [](directive)
directives[directive]
end
|
#accept(visitor:) ⇒ Object
Dependencies need to be rendered before their dependants; that’s handled here. Subclasses should run ‘super` before doing anything else with the Visitor, or call the send_to_dependencies method directly, so that this happens properly!
53
54
55
|
# File 'lib/litbuild/blueprint.rb', line 53
def accept(visitor:)
send_to_dependencies(visitor: visitor)
end
|
#deduped_dependency_names ⇒ Object
If a dependency is declared both without a phase (typically in the base directives for the blueprint) and with a phase (typically in # a phase of that blueprint), throw away the phaseless declaration to avoid including two versions of the dependency.
159
160
161
162
163
164
165
166
167
|
# File 'lib/litbuild/blueprint.rb', line 159
def deduped_dependency_names
dep_names = self['depends-on'].clone || []
deps_with_phase = dep_names.select { |dep| dep.include?('::') }
deps_with_phase.each do |dep|
dep_without_phase = dep.split('::')[0]
dep_names.delete(dep_without_phase)
end
dep_names
end
|
#directives ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/litbuild/blueprint.rb', line 79
def directives
if active_phase
@phase_directives[active_phase]
else
@base_directives
end
end
|
#failure_line ⇒ Object
149
150
151
|
# File 'lib/litbuild/blueprint.rb', line 149
def failure_line
'FAILURE'
end
|
#file_name ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/litbuild/blueprint.rb', line 116
def file_name
if active_phase
"#{name}-#{active_phase}"
else
name
end.tr(' ', '-')
end
|
#for_phase(new_active_phase) ⇒ Object
Return a copy of this blueprint that is initialized to operate on the specified phase.
59
60
61
62
63
64
65
|
# File 'lib/litbuild/blueprint.rb', line 59
def for_phase(new_active_phase)
return self unless phases?
phased_blueprint = clone
phased_blueprint.phase = new_active_phase if new_active_phase
phased_blueprint
end
|
#full_name ⇒ Object
112
113
114
|
# File 'lib/litbuild/blueprint.rb', line 112
def full_name
value('full-name')
end
|
124
125
126
|
# File 'lib/litbuild/blueprint.rb', line 124
def
value('full-name')
end
|
128
129
130
|
# File 'lib/litbuild/blueprint.rb', line 128
def
"#{} (#{active_phase} phase)"
end
|
#logfile(stage_name, phase_name = nil) ⇒ Object
132
133
134
135
|
# File 'lib/litbuild/blueprint.rb', line 132
def logfile(stage_name, phase_name = nil)
phase = phase_name&.tr(' ', '_')
@logfile_namer.path_for(name, phase, stage_name)
end
|
#name ⇒ Object
100
101
102
|
# File 'lib/litbuild/blueprint.rb', line 100
def name
value('name')
end
|
#name_with_phase ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/litbuild/blueprint.rb', line 104
def name_with_phase
if active_phase
"#{name}::#{active_phase}"
else
name
end
end
|
#phase_grafs ⇒ Object
75
76
77
|
# File 'lib/litbuild/blueprint.rb', line 75
def phase_grafs
@phase_grafs[active_phase]
end
|
#phases ⇒ Object
67
68
69
|
# File 'lib/litbuild/blueprint.rb', line 67
def phases
@phase_directives.keys
end
|
#phases? ⇒ Boolean
71
72
73
|
# File 'lib/litbuild/blueprint.rb', line 71
def phases?
!@phase_directives.empty?
end
|
#success_line ⇒ Object
145
146
147
|
# File 'lib/litbuild/blueprint.rb', line 145
def success_line
'SUCCESS'
end
|
#target_name ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/litbuild/blueprint.rb', line 137
def target_name
if active_phase
"#{name}::#{active_phase}"
else
name
end
end
|
#value(directive) ⇒ Object
This is just like the [] operator method except that it always returns only the first value for a directive – which is helpful for all the directives that are only ever supposed to have a single value, like ‘name` or `full-name`.
96
97
98
|
# File 'lib/litbuild/blueprint.rb', line 96
def value(directive)
self[directive]&.first
end
|