Module: Quant::Attributes
- Included in:
- Indicators::IndicatorPoint
- Defined in:
- lib/quant/attributes.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
-
.deregister(klass) ⇒ Object
Removes the given class from the registry.
-
.included(base) ⇒ Object
:nodoc:.
-
.register(klass, name, key, default) ⇒ Object
Registers an attribute for a class in the registry.
-
.registry ⇒ Hash
Tracks all defined attributes, allowing child classes to inherit their parent’s attributes.
Class Method Details
.deregister(klass) ⇒ Object
Removes the given class from the registry. Useful for testing.
27 28 29 |
# File 'lib/quant/attributes.rb', line 27 def self.deregister(klass) registry.delete(klass) end |
.included(base) ⇒ Object
:nodoc:
129 130 131 132 |
# File 'lib/quant/attributes.rb', line 129 def self.included(base) # :nodoc: base.extend(ClassMethods) base.prepend(InstanceMethods) end |
.register(klass, name, key, default) ⇒ Object
Registers an attribute for a class in the registry. Internal use only.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/quant/attributes.rb', line 38 def self.register(klass, name, key, default) # Disallow redefining or replacing a key as it is easy to miss the overwrite # and leads to serialization surprises. if key && registry.values.flat_map(&:values).map{ |entry| entry[:key] }.include?(key) raise Errors::DuplicateAttributesKeyError, "Attribute Key #{key} already defined!" end registry[klass] ||= {} registry[klass][name] = { key: key, default: default } end |
.registry ⇒ Hash
Tracks all defined attributes, allowing child classes to inherit their parent’s attributes. The registry key is the class registering an attrbritute and is itself a hash of the attribute name and the attribute’s key and default value. Internal use only.
22 23 24 |
# File 'lib/quant/attributes.rb', line 22 def self.registry @registry ||= {} end |