Module: Oni::Configurable::ClassMethods

Defined in:
lib/oni/configurable.rb

Instance Method Summary collapse

Instance Method Details

#optionsHash

Returns a Hash containing the options of the current class.

Returns:

  • (Hash)


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

def options
  return @options ||= {}
end

#set(option, value) ⇒ Object

Sets the option to the given value. If a Proc (or any object that responds to #call) is given it's not evaluated until it's accessed. This makes it possible to for example set a logger that's not created until an instance of the including class is created.

Examples:

Setting a regular option

set :number, 10

Setting an option using a proc

# This means the logger won't be shared between different instances of
# the including class.
set :logger, proc { Logger.new(STDOUT) }

Parameters:

  • option (Symbol|String)
  • value (Mixed)


85
86
87
# File 'lib/oni/configurable.rb', line 85

def set(option, value)
  options[option.to_sym] = value
end

#set_multiple(options) ⇒ Object

Sets a number of options based on the given Hash.

Examples:

set_multiple(:a => 10, :b => 20)

Parameters:

  • options (Hash)


97
98
99
100
101
# File 'lib/oni/configurable.rb', line 97

def set_multiple(options)
  options.each do |option, value|
    set(option, value)
  end
end