Module: PlatonicConfig::ClassMethods

Defined in:
lib/platonic_config.rb

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(sym, *args, &block)

Allow calls directly on the object to configuration keys Ex: define_options :foo => bar Class.foo



76
77
78
79
80
81
82
83
84
85
# File 'lib/platonic_config.rb', line 76

def method_missing(sym,*args,&block)
  if @options.has_key? sym
    if args.length == 1
      @options[sym] = args[0]
    end
    @options[sym]
  else
    super
  end
end

Instance Method Details

- (Object) configure {|_self| ... } Also known as: config

convenience method to allow for block level configuration

Yields:

  • (_self)

Yield Parameters:



97
98
99
100
# File 'lib/platonic_config.rb', line 97

def configure
  yield self
  self
end

- (Object) define_options(options = {})

Define the options and defaults for this coniguration



58
59
60
61
# File 'lib/platonic_config.rb', line 58

def define_options(options = {})
  @default_options = options
  reset_defaults
end

- (Object) options

return the set of configured options



64
65
66
# File 'lib/platonic_config.rb', line 64

def options
  @options
end

- (Object) reset_defaults

set all configured options back to their default values



69
70
71
# File 'lib/platonic_config.rb', line 69

def reset_defaults
  @options = @default_options.dup
end

- (Boolean) respond_to?(sym)

Let respond_to? answer for symbols defined in the options

Returns:

  • (Boolean)


88
89
90
91
92
93
94
# File 'lib/platonic_config.rb', line 88

def respond_to?(sym)
  if @options.has_key? sym
    true
  else
    super
  end
end