Module: Threatinator::PropertyDefiner
- Included in:
- Event
- Defined in:
- lib/threatinator/property_definer.rb
Overview
A helper that lets us easily define properties within an object and validate them.
Defined Under Namespace
Modules: ClassMethods
Classes: Property
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
6
7
8
|
# File 'lib/threatinator/property_definer.rb', line 6
def self.included(base)
base.extend(Threatinator::PropertyDefiner::ClassMethods)
end
|
Instance Method Details
#_get(name) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/threatinator/property_definer.rb', line 18
def _get(name)
if _properties.has_key?(name)
return _properties[name]
end
prop = _prop(name)
return nil if prop.nil?
val = prop.default_value
_set(name, val)
val
end
|
#_parse_properties(opts = {}) ⇒ Object
36
37
38
|
# File 'lib/threatinator/property_definer.rb', line 36
def _parse_properties(opts = {})
opts.each { |k, v| _set(k, v) }
end
|
#_prop(name) ⇒ Object
14
15
16
|
# File 'lib/threatinator/property_definer.rb', line 14
def _prop(name)
self.class._properties[name]
end
|
#_properties ⇒ Object
10
11
12
|
# File 'lib/threatinator/property_definer.rb', line 10
def _properties
@_properties ||= Hash.new
end
|
#_set(name, val) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/threatinator/property_definer.rb', line 29
def _set(name, val)
prop = _prop(name)
return if prop.nil?
prop.validate!(self, val)
_properties[name] = val
end
|