Class: Flowlink::ObjectBase
- Inherits:
-
Object
- Object
- Flowlink::ObjectBase
- Defined in:
- lib/flowlink_data/objectbase.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#f_methods ⇒ Object
Base class for any Flowlink objects.
Class Method Summary collapse
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(*overrides) ⇒ ObjectBase
constructor
A new instance of ObjectBase.
- #to_hash ⇒ Object (also: #to_message)
Constructor Details
#initialize(*overrides) ⇒ ObjectBase
Returns a new instance of ObjectBase.
10 11 12 13 14 15 16 17 18 |
# File 'lib/flowlink_data/objectbase.rb', line 10 def initialize(*overrides) unless overrides.flatten!.all? { |arg| arg.is_a?(FieldMethod) } # using array arguments isn't supported anymore fail ArgumentError, 'Arguments need to be FieldMethods' end defaults = FieldMethod.multi_new(fields) @f_methods = FieldMethod.merge(overrides, defaults) end |
Instance Attribute Details
#f_methods ⇒ Object
Base class for any Flowlink objects. Children should implement self.fields internally.
8 9 10 |
# File 'lib/flowlink_data/objectbase.rb', line 8 def f_methods @f_methods end |
Class Method Details
.fields ⇒ Object
26 27 28 29 |
# File 'lib/flowlink_data/objectbase.rb', line 26 def self.fields # A list of fields that the object should have. fail NotImplementedError end |
Instance Method Details
#fields ⇒ Object
31 32 33 |
# File 'lib/flowlink_data/objectbase.rb', line 31 def fields @fields ||= self.class.fields end |
#to_hash ⇒ Object Also known as: to_message
20 21 22 |
# File 'lib/flowlink_data/objectbase.rb', line 20 def to_hash Hash[@f_methods.map { |fm| [fm.method_name.to_s, fm.send_to(self)] }] end |