Class: Sinclair::Config

Inherits:
Object
  • Object
show all
Extended by:
ConfigClass
Defined in:
lib/sinclair/config.rb,
lib/sinclair/config/methods_builder.rb

Overview

Base class for configuration when using Configurable

The methods will be added later by ConfigFactory

The instance variables will be set by ConfigBuilder

Defined Under Namespace

Classes: MethodsBuilder

Instance Method Summary collapse

Methods included from ConfigClass

add_configs, config_attributes

Instance Method Details

#to_hashHash

Return all the current configurations in a hash

Examples:

Checking all hash/json formats

class LoginConfig < Sinclair::Config
  add_configs :password, username: 'bob'
end

config = LoginConfig.new

config.to_hash
# returns { 'password' => nil, 'username' => 'bob' }

config.as_json
# returns { 'password' => nil, 'username' => 'bob' }

config.to_json
# returns '{"password":null,"username":"bob"}'

Returns:

  • (Hash)


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

def to_hash
  self.class.config_attributes.each_with_object({}) do |attribute, hash|
    hash[attribute.to_s] = public_send(attribute)
  end
end