Class: Beni::DSL::DefinitionContext
- Inherits:
-
Object
- Object
- Beni::DSL::DefinitionContext
- Defined in:
- lib/beni/dsl/definition_context.rb
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) ⇒ Object
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) ⇒ Object
-
#to_definition ⇒ Object
The collected definition; raises when the block left
versionorsha256undeclared. - #version(value) ⇒ Object
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) ⇒ Object
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) ⇒ Object
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 ⇒ Object
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) ⇒ Object
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 |