Class: Stix2::Common
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Stix2::Common
- Includes:
- Hashie::Extensions::Dash::Coercion, Hashie::Extensions::Dash::PredefinedValues, Hashie::Extensions::IndifferentAccess
- Defined in:
- lib/stix2/common.rb
Direct Known Subclasses
Bundle, Stix2::CyberobservableObject::Base, DomainObject::Base, MetaObject::Base, MetaObject::DataMarking::MarkingDefinition, RelationshipObject::Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Common
constructor
A new instance of Common.
- #method_missing(m, *args, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Common
Returns a new instance of Common.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/stix2/common.rb', line 23 def initialize( = {}) Hashie.symbolize_keys!() type = to_dash(self.class.name.split('::').last) if [:type] raise("Property 'type' must be '#{type}'") if [:type] != type else [:type] = type end super() Stix2.storage_add(self) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/stix2/common.rb', line 35 def method_missing(m, *args, &block) super(m, args, block) if !m.to_s.end_with?('_instance') # Retrieve the original method ref_method = m.to_s.gsub(/_instance$/, '') obj = send(ref_method) raise("Can't get a Stix2::Identifier from #{ref_method}") if !obj.is_a?(Stix2::Identifier) Stix2.storage_find(obj) end |