Sha256: da15c8c1b888975fd70b9b45ccc043f6d0da4bed64fbbe3e1afff2de1c06279e

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

class Sinclair
  # Base class for configuration when using {Configurable}
  #
  # The methods will be added later by {ConfigFactory}
  #
  # The instance variables will be set by {ConfigBuilder}
  class Config
    autoload :MethodsBuilder, 'sinclair/config/methods_builder'
    extend ConfigClass

    # Return all the current configurations in a hash
    #
    # @return [Hash]
    #
    # @example 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"}'
    def to_hash
      self.class.config_attributes.each_with_object({}) do |attribute, hash|
        hash[attribute.to_s] = public_send(attribute)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinclair-1.4.1 lib/sinclair/config.rb
sinclair-1.4.0 lib/sinclair/config.rb