Class: Meta::Utils::Kwargs::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/meta/utils/kwargs/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



29
30
31
32
# File 'lib/meta/utils/kwargs/builder.rb', line 29

def initialize
  @arguments = []
  @handle_extras = ExtrasConsumers::RaiseError
end

Class Method Details

.build(base_checker = nil, &block) ⇒ Object



54
55
56
57
58
# File 'lib/meta/utils/kwargs/builder.rb', line 54

def self.build(base_checker = nil, &block)
  builder = Builder.new
  builder.instance_exec &block
  builder.build(base_checker&.arguments_consumer)
end

Instance Method Details

#after_handler(&blk) ⇒ Object



44
45
46
# File 'lib/meta/utils/kwargs/builder.rb', line 44

def after_handler(&blk)
  @after_handler = blk
end

#build(base_consumer = nil) ⇒ Object



48
49
50
51
52
# File 'lib/meta/utils/kwargs/builder.rb', line 48

def build(base_consumer = nil)
  consumers = [base_consumer, *@arguments].compact
  consumers = CompositeConsumer.new(*consumers)
  Checker.new(arguments_consumer: consumers, extras_consumer: @handle_extras, after_handler: @after_handler)
end

#handle_extras(sym) ⇒ Object



40
41
42
# File 'lib/meta/utils/kwargs/builder.rb', line 40

def handle_extras(sym)
  @handle_extras = ExtrasConsumers.resolve_handle_extras(sym)
end

#key(*names, **options) ⇒ Object



34
35
36
37
38
# File 'lib/meta/utils/kwargs/builder.rb', line 34

def key(*names, **options)
  names.each do |name|
    @arguments << ArgumentConsumer.new(name: name, **options)
  end
end