Class: OFX::Base::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/ofx_kit/base/entity.rb

Overview

Abstract base for domain objects that support dynamic field mappings and relationship wiring via Base::Builder.

Subclasses gain two class-level macros:

  • .ensure_attribute — dynamically adds attr_accessor for custom mapped fields

  • .wired_by_builder — declares nil-returning placeholder methods that Base::Builder#wire_relations overrides per-instance at build time

Direct Known Subclasses

OFX::Balance, Account, Transaction

Class Method Summary collapse

Class Method Details

.ensure_attribute(name) ⇒ Object

Ensures the given attribute exists on the class, adding attr_accessor if needed. Called by Base::Builder when applying custom field mappings. name is an attribute name (String or Symbol).



18
19
20
# File 'lib/ofx_kit/base/entity.rb', line 18

def self.ensure_attribute(name)
  attr_accessor name.to_sym unless method_defined?(name)
end

.wired_by_builder(*names) ⇒ Object

Declares one or more placeholder instance methods that return nil. Base::Builder replaces each with a singleton method on the built instance that returns the wired relation. names is an Array of Symbol relation names to declare.



27
28
29
# File 'lib/ofx_kit/base/entity.rb', line 27

def self.wired_by_builder(*names)
  names.each { |name| define_method(name) { nil } }
end