Class: Vial::Definition::AttributeBuilder
- Inherits:
-
Object
- Object
- Vial::Definition::AttributeBuilder
show all
- Defined in:
- lib/vial/definition.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AttributeBuilder.
343
344
345
346
|
# File 'lib/vial/definition.rb', line 343
def initialize(definition)
@definition = definition
@attributes = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
# File 'lib/vial/definition.rb', line 362
def method_missing(name, *args, &block)
if block
@attributes[name.to_s] = CallableValue.new(&block)
return
end
if args.length != 1
raise ArgumentError, "Expected a single value for #{name}"
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: args.first,
source_file: source_file,
source_line: loc&.lineno
)
else
@attributes[name.to_s] = args.first
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
341
342
343
|
# File 'lib/vial/definition.rb', line 341
def attributes
@attributes
end
|
Instance Method Details
#erb(source) ⇒ Object
358
359
360
|
# File 'lib/vial/definition.rb', line 358
def erb(source)
Erb.new(source: source)
end
|
#id(value) ⇒ Object
348
349
350
351
352
353
354
355
356
|
# File 'lib/vial/definition.rb', line 348
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
|
#respond_to_missing?(*_args) ⇒ Boolean
385
386
387
|
# File 'lib/vial/definition.rb', line 385
def respond_to_missing?(*_args)
true
end
|
#sequence(name, start: 1, &block) ⇒ Object
389
390
391
|
# File 'lib/vial/definition.rb', line 389
def sequence(name, start: 1, &block)
@definition.sequence(name, start: start, &block)
end
|