Module: PlatonicConfig

Defined in:
lib/platonic_config/version.rb,
lib/platonic_config.rb

Overview

Placeholder module for versioning

Defined Under Namespace

Modules: ClassMethods

Constant Summary

VERSION =

Version of the module

"0.1.1"

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

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



31
32
33
34
35
36
37
38
39
40
# File 'lib/platonic_config.rb', line 31

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

Class Method Details

.included(base) ⇒ Object

Set up configuration methodss on the base class



24
25
26
# File 'lib/platonic_config.rb', line 24

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

Instance Method Details

#configure {|_self| ... } ⇒ Object Also known as: config

convenience method to allow for block level configuration

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
# File 'lib/platonic_config.rb', line 17

def configure
  yield self
  self
end

#instance_optionsObject

return just the options set on the instance



12
13
14
# File 'lib/platonic_config.rb', line 12

def instance_options
  @options ||= {}
end

#optionsObject

Give the options defined on the instance merged with the class-level defaults



7
8
9
# File 'lib/platonic_config.rb', line 7

def options
  self.class.options.merge instance_options
end

#reset_defaultsObject

Reset all config values set on the instance



52
53
54
# File 'lib/platonic_config.rb', line 52

def reset_defaults
  @options = {}
end

#respond_to?(sym) ⇒ Boolean

Let respond_to? answer for symbols defined in the options

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/platonic_config.rb', line 43

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