Module: Pray::ManifestMethods::ParserBlocks
- Included in:
- BlockParser
- Defined in:
- lib/pray/manifest_parser_blocks.rb
Instance Method Summary collapse
- #apply_destination_statement(manifest, statement, index, mode) ⇒ Object
- #apply_file_body_statement(manifest, statement, file_path) ⇒ Object
- #apply_local_pray_path(manifest, first, keywords, values, destination_index) ⇒ Object
- #apply_pray_statement(manifest, rest, destination_index) ⇒ Object
- #bind_compose_local(manifest, index, rest) ⇒ Object
- #bind_file_package(manifest, rest, file_path) ⇒ Object
- #bind_pray_package(manifest, package, destination_index) ⇒ Object
- #package_signal?(values, keywords) ⇒ Boolean
- #parse_destination_block(manifest, rest, mode) ⇒ Object
- #parse_destination_body(manifest, index, mode) ⇒ Object
- #parse_file_block(manifest, rest) ⇒ Object
- #parse_file_body(manifest, file_path) ⇒ Object
- #parse_group_block(manifest) ⇒ Object
- #parse_symbols_block(manifest) ⇒ Object
- #parse_target_block(manifest, target_index) ⇒ Object
Instance Method Details
#apply_destination_statement(manifest, statement, index, mode) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pray/manifest_parser_blocks.rb', line 76 def apply_destination_statement(manifest, statement, index, mode) if (match = statement.match(/\Aagent (.+)\z/)) manifest.note_deprecated_keyword("agent") apply_pray_statement(manifest, match[1], index) return end if (match = statement.match(/\A(?:pray|use|include|package) (.+)\z/)) apply_pray_statement(manifest, match[1], index) return end if mode == "compose" && (match = statement.match(/\Alocal (.+)\z/)) bind_compose_local(manifest, index, match[1]) return end raise Error.parse("manifest", "unsupported statement inside destination block: #{statement}") end |
#apply_file_body_statement(manifest, statement, file_path) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/pray/manifest_parser_blocks.rb', line 126 def apply_file_body_statement(manifest, statement, file_path) if (match = statement.match(/\Aagent (.+)\z/)) manifest.note_deprecated_keyword("agent") bind_file_package(manifest, match[1], file_path) return true end if (match = statement.match(/\A(?:pray|use|include|package) (.+)\z/)) bind_file_package(manifest, match[1], file_path) return true end raise Error.parse("manifest", "unsupported statement inside file block: #{statement}") end |
#apply_local_pray_path(manifest, first, keywords, values, destination_index) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/pray/manifest_parser_blocks.rb', line 161 def apply_local_pray_path(manifest, first, keywords, values, destination_index) return false if package_signal?(values, keywords) return false unless Destination.local_path_form?(first) in_compose = destination_index && manifest.targets[destination_index]&.mode == "compose" unless in_compose raise Error.parse("manifest", "local pray paths are only valid inside compose blocks") end local = ManifestLocal.new(path: first, position: "after", optional: false, bound: true) Destination.bind_local_entry(manifest.targets[destination_index], local.path) Destination.upsert_local(manifest, local) true end |
#apply_pray_statement(manifest, rest, destination_index) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/pray/manifest_parser_blocks.rb', line 150 def apply_pray_statement(manifest, rest, destination_index) values, keywords = parse_call(rest) raise Error.parse("manifest", "pray missing package or path") if values.empty? first = string_from_value(values.first) return if apply_local_pray_path(manifest, first, keywords, values, destination_index) package = parse_package_with_groups(rest) bind_pray_package(manifest, package, destination_index) end |
#bind_compose_local(manifest, index, rest) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/pray/manifest_parser_blocks.rb', line 93 def bind_compose_local(manifest, index, rest) local = parse_local_decl(rest) local.bound = true Destination.bind_local_entry(manifest.targets[index], local.path) Destination.upsert_local(manifest, local) end |
#bind_file_package(manifest, rest, file_path) ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/pray/manifest_parser_blocks.rb', line 139 def bind_file_package(manifest, rest, file_path) package = parse_package_with_groups(rest) if package.file raise Error.parse("manifest", "file: keyword is invalid inside a file block") end package.file = file_path package.bound = true package.roles << "file" unless package.roles.include?("file") Destination.upsert_package(manifest, package) end |
#bind_pray_package(manifest, package, destination_index) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/pray/manifest_parser_blocks.rb', line 184 def bind_pray_package(manifest, package, destination_index) if package.file if destination_index raise Error.parse("manifest", "file: is mutually exclusive with compose/tree nesting") end package.bound = true package.roles << "file" unless package.roles.include?("file") end if destination_index mode = manifest.targets[destination_index].mode package.bound = true role = Destination.role_for_destination(mode) package.roles << role if role && !package.roles.include?(role) Destination.bind_package_entry(manifest.targets[destination_index], package.name) end Destination.upsert_package(manifest, package) end |
#package_signal?(values, keywords) ⇒ Boolean
177 178 179 180 181 182 |
# File 'lib/pray/manifest_parser_blocks.rb', line 177 def package_signal?(values, keywords) return true if values.length > 1 %w[source export exports file optional path git tag rev tarball oci targets features] .any? { |key| keywords.key?(key) } end |
#parse_destination_block(manifest, rest, mode) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pray/manifest_parser_blocks.rb', line 51 def parse_destination_block(manifest, rest, mode) unless rest.rstrip.end_with?("do") label = (mode == "compose") ? "compose" : "tree" raise Error.parse("manifest", "#{label} must use a block") end header = rest.sub(/\s*do\z/, "").strip values, = parse_call(header) raise Error.parse("manifest", "destination missing path") if values.empty? path = string_from_value(values.first) manifest.targets << Destination.new_destination_target(mode, path) index = manifest.targets.length - 1 parse_destination_body(manifest, index, mode) end |
#parse_destination_body(manifest, index, mode) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/pray/manifest_parser_blocks.rb', line 67 def parse_destination_body(manifest, index, mode) while (statement = next_statement) return if statement == "end" apply_destination_statement(manifest, statement, index, mode) end raise Error.parse("manifest", "missing 'end' for destination block") end |
#parse_file_block(manifest, rest) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/pray/manifest_parser_blocks.rb', line 100 def parse_file_block(manifest, rest) unless rest.rstrip.end_with?("do") raise Error.parse("manifest", "file must use a block (or use pray ..., file: \"path\")") end header = rest.sub(/\s*do\z/, "").strip values, = parse_call(header) raise Error.parse("manifest", "file block missing path") if values.empty? parse_file_body(manifest, string_from_value(values.first)) end |
#parse_file_body(manifest, file_path) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pray/manifest_parser_blocks.rb', line 112 def parse_file_body(manifest, file_path) saw_package = false while (statement = next_statement) if statement == "end" unless saw_package raise Error.parse("manifest", "file block requires a pray package declaration") end return end saw_package = true if apply_file_body_statement(manifest, statement, file_path) end raise Error.parse("manifest", "missing 'end' for file block") end |
#parse_group_block(manifest) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pray/manifest_parser_blocks.rb', line 31 def parse_group_block(manifest) while (statement = next_statement) return if statement == "end" if (match = statement.match(/\Aagent (.+)\z/)) manifest.note_deprecated_keyword("agent") Destination.upsert_package(manifest, parse_package_with_groups(match[1])) elsif (match = statement.match(/\A(?:package|pray|use|include) (.+)\z/)) Destination.upsert_package(manifest, parse_package_with_groups(match[1])) elsif /\Agroup (.+)\z/.match?(statement) raise Error.parse("manifest", "nested group blocks are not supported") else raise Error.parse( "manifest", "group blocks only support agent, package, or pray declarations: #{statement}" ) end end raise Error.parse("manifest", "missing 'end' for group block") end |
#parse_symbols_block(manifest) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pray/manifest_parser_blocks.rb', line 6 def parse_symbols_block(manifest) while (statement = next_statement) return if statement == "end" assignment = StatementSurface.split_symbol_assignment(statement) unless assignment raise Error.parse( "manifest", "unsupported statement inside pray/template block: #{statement}" ) end key, value_literal = assignment unless Substitute.pray_symbol_key?(key) raise Error.parse("manifest", "invalid pray symbol key `#{key}`") end if manifest.symbols.key?(key) raise Error.parse("manifest", "duplicate pray symbol `#{key}`") end manifest.symbols[key] = string_from_literal(value_literal) end raise Error.parse("manifest", "missing 'end' for pray/template block") end |
#parse_target_block(manifest, target_index) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/pray/manifest_parser_blocks.rb', line 202 def parse_target_block(manifest, target_index) while (statement = next_statement) return if statement == "end" target = manifest.targets[target_index] raise Error.manifest("target index out of range") unless target manifest.note_deprecated_keyword("output") if statement.start_with?("output ") apply_target_statement(target, statement) end raise Error.parse("manifest", "missing 'end' for target block") end |