Module: Settingable::Settings

Extended by:
Forwardable
Defined in:
lib/settingable/settings.rb

Overview

A module containing the settings configuration.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Method missing. For set methods, it maps to the :[]= method; for regular methods (i.e. not bang or ? methods), it maps to the :[] method.

Returns:

  • (Object)


74
75
76
77
# File 'lib/settingable/settings.rb', line 74

def method_missing(method, *args, &block)
  return super if args.length > 1 || block_given? || method =~ /(\?|\!)\z/
  map_method(method, args)
end

Class Method Details

.included(base) ⇒ Object



44
45
46
# File 'lib/settingable/settings.rb', line 44

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#build { ... } ⇒ self

Builds the settings construct. It yields itself, and then returns itself.

Yields:

Returns:

  • (self)


64
65
66
67
# File 'lib/settingable/settings.rb', line 64

def build
  yield self
  self
end

#initialize(settings = {}) ⇒ Object

Initialize the settings. Merges the given settings to the default settings.

Parameters:

  • settings (Hash) (defaults to: {})

    The initial settings.



55
56
57
# File 'lib/settingable/settings.rb', line 55

def initialize(settings = {})
  @settings = Settingable::Hash.new(merged_settings(settings))
end

#responds_to_missing?(method, _include_all = false) ⇒ Boolean

A hook method for ruby. This should not be called directly. It lets ruby know that we respond to certain methods.

Parameters:

  • method (Symbol)

    The method to check.

Returns:

  • (Boolean)


84
85
86
# File 'lib/settingable/settings.rb', line 84

def responds_to_missing?(method, _include_all = false)
  !(method =~ /(\?|\!)\z/)
end