Class: Beni::DSL::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/beni/dsl/context.rb

Overview

Top-level vocabulary of the Beni::Tasks.new block. Collects the scalar settings, target declarations, and toolchain definitions —validating each declaration eagerly — and resolves them into the Configuration the task-definition phase consumes.

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



10
11
12
13
14
# File 'lib/beni/dsl/context.rb', line 10

def initialize
  @settings = {}
  @targets = {}
  @definitions = {}
end

Instance Method Details

#build_config(path) ⇒ Object



20
21
22
# File 'lib/beni/dsl/context.rb', line 20

def build_config(path)
  declare_scalar(:build_config, path)
end

#configurationObject

Resolve the collected declarations (SPEC.md Behaviors: selection is reference-driven; defaults fall to the built-in pairs).



55
56
57
58
59
60
61
62
# File 'lib/beni/dsl/context.rb', line 55

def configuration
  Configuration.new(
    vendor_dir: resolved_vendor_dir,
    build_config: resolved_build_config,
    targets: resolved_targets,
    toolchains: selected_names.map { |name| selected_toolchain(name) }
  )
end

#target(name, &block) ⇒ Object

A target <name> declaration; the optional block holds the target’s toolchain references.

Raises:



30
31
32
33
34
35
36
37
# File 'lib/beni/dsl/context.rb', line 30

def target(name, &block)
  key = name.to_s
  raise Error, "duplicate `target` declaration #{key.inspect}" if @targets.key?(key)

  # @type var references: Array[String]
  references = block ? TargetContext.collect(&block) : []
  @targets[key] = Target.new(name: key, references: references)
end

#toolchain(name, &block) ⇒ Object

A top-level toolchain <name> — always a definition, so the block is part of the grammar and mruby is never definable.

Raises:



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/beni/dsl/context.rb', line 41

def toolchain(name, &block)
  raise Error, "top-level `toolchain #{name.inspect}` must carry a definition block" unless block
  if name == "mruby"
    raise Error, "a toolchain definition never names \"mruby\" — select it with the `version` setting"
  end

  DSL.assert_known_toolchain!(name)
  raise Error, "duplicate toolchain definition #{name.inspect}" if @definitions.key?(name)

  @definitions[name] = DefinitionContext.collect(name, &block)
end

#vendor_dir(path) ⇒ Object



24
25
26
# File 'lib/beni/dsl/context.rb', line 24

def vendor_dir(path)
  declare_scalar(:vendor_dir, path)
end

#version(value) ⇒ Object



16
17
18
# File 'lib/beni/dsl/context.rb', line 16

def version(value)
  declare_scalar(:version, value)
end