Class: Beni::DSL::DefinitionContext
- Inherits:
-
Object
- Object
- Beni::DSL::DefinitionContext
- Defined in:
- lib/beni/dsl/definition_context.rb,
sig/beni/dsl/definition_context.rbs
Overview
Vocabulary inside a top-level toolchain <name> do … end block —
the (version, sha256) pair and nothing else. Both fields are
required exactly once; the check runs when the block returns.
Class Method Summary collapse
-
.collect(name) { ... } ⇒ ToolchainDefinition
Run
blockon a fresh context and return the collected ToolchainDefinition.
Instance Method Summary collapse
-
#initialize(name) ⇒ DefinitionContext
constructor
A new instance of DefinitionContext.
- #sha256(value) ⇒ void
-
#to_definition ⇒ ToolchainDefinition
The collected definition; raises when the block left
versionorsha256undeclared. - #version(value) ⇒ void
Constructor Details
#initialize(name) ⇒ DefinitionContext
Returns a new instance of DefinitionContext.
17 18 19 20 21 |
# File 'lib/beni/dsl/definition_context.rb', line 17 def initialize(name) @name = name @version = nil @sha256 = nil end |
Class Method Details
.collect(name) { ... } ⇒ ToolchainDefinition
Run block on a fresh context and return the collected
ToolchainDefinition.
11 12 13 14 15 |
# File 'lib/beni/dsl/definition_context.rb', line 11 def self.collect(name, &) context = new(name) context.instance_exec(&) context.to_definition end |
Instance Method Details
#sha256(value) ⇒ void
This method returns an undefined value.
29 30 31 32 33 |
# File 'lib/beni/dsl/definition_context.rb', line 29 def sha256(value) raise Error, "duplicate `sha256` in toolchain #{@name.inspect} definition" if @sha256 @sha256 = value end |
#to_definition ⇒ ToolchainDefinition
The collected definition; raises when the block left version
or sha256 undeclared.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/beni/dsl/definition_context.rb', line 37 def to_definition version = @version sha256 = @sha256 if version.nil? || sha256.nil? missing = [("version" if version.nil?), ("sha256" if sha256.nil?)].compact raise Error, "toolchain #{@name.inspect} definition missing #{missing.join(" and ")}" end ToolchainDefinition.new(name: @name, version: version, sha256: sha256) end |
#version(value) ⇒ void
This method returns an undefined value.
23 24 25 26 27 |
# File 'lib/beni/dsl/definition_context.rb', line 23 def version(value) raise Error, "duplicate `version` in toolchain #{@name.inspect} definition" if @version @version = value end |