Class: Mxrb::Dsl::Builder

Inherits:
Object
  • Object
show all
Includes:
ConnectorDeclarations
Defined in:
lib/mxrb/dsl/builder.rb

Instance Method Summary collapse

Methods included from ConnectorDeclarations

#connector, #connector_plans, #connector_requests, #validate_connector_requests!

Constructor Details

#initialize(path) ⇒ Builder

Returns a new instance of Builder.



275
276
277
278
279
280
281
282
283
284
285
# File 'lib/mxrb/dsl/builder.rb', line 275

def initialize(path)
  @path              = path
  @mendix_version    = "10.18.0"
  @modules           = []
  @security          = nil
  @navigation        = nil
  @design_system     = nil
  @native_units_path = nil
  @native_unit_overrides = []
  @project_assets = nil
end

Instance Method Details

#bson_binary(base64, subtype: :generic) ⇒ Object



338
339
340
# File 'lib/mxrb/dsl/builder.rb', line 338

def bson_binary(base64, subtype: :generic)
  BSON::Binary.new(Base64.strict_decode64(base64), subtype)
end

#build!Object



352
353
354
355
356
357
# File 'lib/mxrb/dsl/builder.rb', line 352

def build!
  validate_connector_requests!
  validate!
  Writer.new(@path, definition).write!
  self
end

#definitionObject



367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/mxrb/dsl/builder.rb', line 367

def definition
  {
    version: @mendix_version,
    modules: @modules.map(&:to_h),
    security: @security,
    navigation: @navigation,
    design_system: @design_system,
    connectors: connector_requests.map(&:to_h),
    project_assets: @project_assets,
    native_units_path: @native_units_path,
    native_unit_overrides: @native_unit_overrides
  }
end

#design_system(&block) ⇒ Object



309
310
311
312
313
# File 'lib/mxrb/dsl/builder.rb', line 309

def design_system(&block)
  builder = DesignSystemBuilder.new
  builder.instance_eval(&block) if block
  @design_system = builder.to_h
end

#evaluate(path) ⇒ Object



342
343
344
# File 'lib/mxrb/dsl/builder.rb', line 342

def evaluate(path)
  instance_eval(File.read(path), path, 1)
end

#evaluate_dir(dir) ⇒ Object



346
347
348
349
350
# File 'lib/mxrb/dsl/builder.rb', line 346

def evaluate_dir(dir)
  return unless File.directory?(dir)

  Dir[File.join(dir, '*.rb')].sort.each { |path| evaluate(path) }
end

#graphObject



359
360
361
# File 'lib/mxrb/dsl/builder.rb', line 359

def graph
  Architecture::Graph.new(definition)
end

#mendix_version(v) ⇒ Object



287
288
289
# File 'lib/mxrb/dsl/builder.rb', line 287

def mendix_version(v)
  @mendix_version = v
end

#module(name, &block) ⇒ Object



291
292
293
294
295
# File 'lib/mxrb/dsl/builder.rb', line 291

def module(name, &block)
  mod = ModuleBuilder.new(name)
  mod.instance_eval(&block) if block
  @modules << mod
end

#native_unit(unit_id, container_id:, containment:, deep_structure:, module_name: nil) ⇒ Object

Raises:

  • (ArgumentError)


326
327
328
329
330
331
332
333
334
335
336
# File 'lib/mxrb/dsl/builder.rb', line 326

def native_unit(unit_id, container_id:, containment:, deep_structure:, module_name: nil)
  raise ArgumentError, "deep_structure requires a Hash" unless deep_structure.is_a?(Hash)

  @native_unit_overrides << {
    unit_id: unit_id.to_s,
    container_id: container_id.to_s,
    containment: containment.to_s,
    module: module_name&.to_s,
    doc: deep_structure
  }
end

#native_units(path) ⇒ Object



315
316
317
# File 'lib/mxrb/dsl/builder.rb', line 315

def native_units(path)
  @native_units_path = path
end


303
304
305
306
307
# File 'lib/mxrb/dsl/builder.rb', line 303

def navigation(&block)
  builder = NavigationBuilder.new
  builder.instance_eval(&block) if block
  @navigation = builder.to_h
end

#project_assets(manifest, root:) ⇒ Object



319
320
321
322
323
324
# File 'lib/mxrb/dsl/builder.rb', line 319

def project_assets(manifest, root:)
  @project_assets = {
    manifest: File.expand_path(manifest),
    root: File.expand_path(root)
  }
end

#security(&block) ⇒ Object



297
298
299
300
301
# File 'lib/mxrb/dsl/builder.rb', line 297

def security(&block)
  builder = SecurityBuilder.new
  builder.instance_eval(&block) if block
  @security = builder.to_h
end

#validate!Object



363
364
365
# File 'lib/mxrb/dsl/builder.rb', line 363

def validate!
  Architecture::Validator.new(graph).validate!
end