Class: Cornucopia::Util::GenericSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/cornucopia/util/generic_settings.rb

Overview

This is a stupid little settings class Basicaly, anything you send to it is put into a hash or returned from a hash.

Instance Method Summary collapse

Constructor Details

#initializeGenericSettings

Returns a new instance of GenericSettings.



8
9
10
# File 'lib/cornucopia/util/generic_settings.rb', line 8

def initialize
  @settings_hash = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cornucopia/util/generic_settings.rb', line 12

def method_missing(method_sym, *arguments, &block)
  if self.respond_to?("super__#{method_sym}".to_sym)
    super
  else
    if method_sym.to_s[-1] == "="
      raise "wrong number of arguments (#{arguments.length} for 1)" if !arguments || arguments.length != 1
      raise "block not accepted" if block

      @settings_hash[method_sym.to_s[0..-2].to_sym] = arguments[0]
    else
      raise "too many arguments (#{arguments.length} for 0)" if arguments && arguments.length > 0
      raise "block not accepted" if block
      @settings_hash[method_sym]
    end
  end
end

Instance Method Details

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/cornucopia/util/generic_settings.rb', line 29

def respond_to?(method_sym, include_private = false)
  method_name = method_sym.to_s
  if method_name[0.."super__".length - 1] == "super__"
    super(method_sym["super__".length..-1].to_sym, include_private)
  else
    true
  end
end