Module: Settingable::Settings

Extended by:
Forwardable
Includes:
Comparable, Enumerable
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)


78
79
80
81
# File 'lib/settingable/settings.rb', line 78

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)


68
69
70
71
# File 'lib/settingable/settings.rb', line 68

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.



59
60
61
# File 'lib/settingable/settings.rb', line 59

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)


88
89
90
# File 'lib/settingable/settings.rb', line 88

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