Class: Vial::Definition::IncludeOverrideBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/vial/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ IncludeOverrideBuilder

Returns a new instance of IncludeOverrideBuilder.



397
398
399
400
# File 'lib/vial/definition.rb', line 397

def initialize(definition)
  @definition = definition
  @attributes = {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



395
396
397
# File 'lib/vial/definition.rb', line 395

def attributes
  @attributes
end

Instance Method Details

#erb(source) ⇒ Object



402
403
404
# File 'lib/vial/definition.rb', line 402

def erb(source)
  Erb.new(source: source)
end

#id(value) ⇒ Object



406
407
408
409
410
411
412
413
414
# File 'lib/vial/definition.rb', line 406

def id(value)
  loc = caller_locations(1, 1).first
  source_file = loc&.absolute_path || loc&.path
  @attributes[@definition.primary_key] = ExplicitId.new(
    value: value,
    source_file: source_file,
    source_line: loc&.lineno
  )
end

#override(name, value = nil, &block) ⇒ Object



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/vial/definition.rb', line 416

def override(name, value = nil, &block)
  if block
    if name.to_s == @definition.primary_key
      loc = caller_locations(1, 1).first
      source_file = loc&.absolute_path || loc&.path
      @attributes[name.to_s] = ExplicitId.new(
        value: CallableValue.new(&block),
        source_file: source_file,
        source_line: loc&.lineno
      )
    else
      @attributes[name.to_s] = CallableValue.new(&block)
    end
    return
  end

  if name.to_s == @definition.primary_key
    loc = caller_locations(1, 1).first
    source_file = loc&.absolute_path || loc&.path
    @attributes[name.to_s] = ExplicitId.new(
      value: value,
      source_file: source_file,
      source_line: loc&.lineno
    )
  else
    @attributes[name.to_s] = value
  end
end

#sequence(name, start: 1, &block) ⇒ Object



445
446
447
# File 'lib/vial/definition.rb', line 445

def sequence(name, start: 1, &block)
  @definition.sequence(name, start: start, &block)
end