Module: Observed::Configurable
Overview
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.
Defined Under Namespace
Modules: ClassMethods, ModuleMethods
Classes: NotConfiguredError
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(klass) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/observed/configurable.rb', line 98
def included(klass)
if klass.is_a? Class
klass.extend ClassMethods
else
klass.extend ModuleMethods
end
end
|
Instance Method Details
11
12
13
14
15
16
17
18
|
# 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) ⇒ Object
Returns In order of precedence, the value of the instance variable named ‘“@” + name`, or the value `@attributes`, or the default value for the attribute named `name`.
28
29
30
|
# 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) ⇒ Boolean
21
22
23
|
# File 'lib/observed/configurable.rb', line 21
def has_attribute_value?(name)
!! get_attribute_value(name)
end
|
#initialize(args = {}) ⇒ Object
7
8
9
|
# File 'lib/observed/configurable.rb', line 7
def initialize(args={})
configure(args)
end
|