Class: LcpRuby::Dsl::DslLoader::EvalContext

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/dsl/dsl_loader.rb

Overview

Isolated evaluation context to prevent DSL files from accessing the DslLoader internals.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvalContext

Returns a new instance of EvalContext.



257
258
259
# File 'lib/lcp_ruby/dsl/dsl_loader.rb', line 257

def initialize
  @definitions = []
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



255
256
257
# File 'lib/lcp_ruby/dsl/dsl_loader.rb', line 255

def definitions
  @definitions
end

Instance Method Details

#define_model(name, inherits: nil, &block) ⇒ Object



261
262
263
264
265
266
267
# File 'lib/lcp_ruby/dsl/dsl_loader.rb', line 261

def define_model(name, inherits: nil, &block)
  builder = ModelBuilder.new(name)
  builder.instance_eval(&block)
  hash = builder.to_hash
  hash["inherits"] = inherits.to_s if inherits
  @definitions << Metadata::ModelDefinition.from_hash(hash)
end