Class: Nina::Builder::Initialization

Inherits:
BasicObject
Defined in:
lib/nina/builder/initialization.rb

Overview

A way to call methods from initalization proc on base_class

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ Initialization

Returns a new instance of Initialization.



7
8
9
10
11
12
# File 'lib/nina/builder/initialization.rb', line 7

def initialize(builder)
  @builder = builder
  @abstract_factory = builder.abstract_factory
  @allow_list = @abstract_factory.factories.keys
  @atts = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, **kwargs, &block) ⇒ Object



14
15
16
17
18
19
# File 'lib/nina/builder/initialization.rb', line 14

def method_missing(method, *args, **kwargs, &block)
  return super unless @allow_list.include?(method)

  @atts[method] ||= @abstract_factory.create(method, *args, **kwargs, &block)
                                     .tap { |o| @builder.send(:update, method, o) }
end

Instance Method Details

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/nina/builder/initialization.rb', line 21

def respond_to_missing?(method, _include_private = false)
  @allow_list.include?(method)
end

#to_hObject



25
26
27
# File 'lib/nina/builder/initialization.rb', line 25

def to_h
  @atts.dup
end