Class: Sinclair::ConfigBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sinclair/config_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class responsible for setting the values on configuration

Examples:

class MyConfig
  extend Sinclair::ConfigClass

  attr_reader :name, :config
end

config = MyConfig.new

builder = Sinclair::ConfigBuilder.new(config, :name)

builder.instance_eval { |c| c.name 'John' }

config.name # returns 'John'

Author:

  • darthjee

Instance Method Summary collapse

Constructor Details

#initialize(config, *config_attributes) ⇒ ConfigBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A new instance of ConfigBuilder

Parameters:

  • config (Sinclair::Config)

    config object to be build config object has no attribute setters (only readers) so all attributes are set as instance variable

  • config_attributes (Array<Symbol>)

    list of attributes that can be set on config (expecting that config has the right attribute readers)



33
34
35
36
# File 'lib/sinclair/config_builder.rb', line 33

def initialize(config, *config_attributes)
  @config = config
  @config_attributes = config_attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Method called for methods missing

When a method is missing, it is expected that it is the name of a variable to be set on config (as long as it was defined in the config_attributes_array)

Parameters:

  • method_name (Symbol)

    name of the method called

  • args (Array<Object>)

    arguments of the call

Returns:



52
53
54
55
56
# File 'lib/sinclair/config_builder.rb', line 52

def method_missing(method_name, *args)
  return super unless method_included?(method_name)

  @config.instance_variable_set("@#{method_name}", *args)
end