module Observed::Configurable
Indicates that classes included this module to have attributes which are configurable. `configurable` means that the attributes can be configured via named parameters of the constructor and the `configure` instance method of the class included this module.
Public Class Methods
included(klass)
click to toggle source
# File lib/observed/configurable.rb, line 98 def included(klass) if klass.is_a? Class klass.extend ClassMethods else klass.extend ModuleMethods end end
new(args={})
click to toggle source
# File lib/observed/configurable.rb, line 7 def initialize(args={}) configure(args) end
Public Instance Methods
configure(args={})
click to toggle source
# File lib/observed/configurable.rb, line 11 def configure(args={}) if @attributes @attributes.merge! args else @attributes ||= args.dup end self end
get_attribute_value(name)
click to toggle source
@param [String|Symbol] name @return [Object] In order of precedence, the value of the instance variable named `“@” + name`,
or the value `@attributes[name]`, or the default value for the attribute named `name`
# File lib/observed/configurable.rb, line 28 def get_attribute_value(name) instance_variable_get("@#{name.to_s}") || @attributes[name] || self.class.defaults[name] end
has_attribute_value?(name)
click to toggle source
@param [String|Symbol] name
# File lib/observed/configurable.rb, line 21 def has_attribute_value?(name) !! get_attribute_value(name) end
Private Instance Methods
fail_for_not_configured_parameter(name)
click to toggle source
# File lib/observed/configurable.rb, line 109 def fail_for_not_configured_parameter(name) fail NotConfiguredError.new("The parameter `#{name}` is not configured. attributes=#{@attributes}, defaults=#{self.class.defaults}") end