Sha256: c9be46e1cfc5e4dab0ccec4515e3a5e4b98e618e39b2cc53e13844c7461eee05
Contents?: true
Size: 1.23 KB
Versions: 12
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true module LedgerSync class ResourceAdaptor module Mixin module ClassMethods def attribute(record_attribute, args = {}) resource_attribute = args.fetch(:resource_attribute, record_attribute) attributes[record_attribute.to_sym] = { record_attribute: record_attribute, resource_attribute: resource_attribute } define_method(resource_attribute) do resource.send(record_attribute) end define_method("#{resource_attribute}=") do |*setter_args| resource.send("#{record_attribute}=", *setter_args) end end def attributes @attributes ||= {} end end module InstanceMethods def initialize(args = {}) @resource = args.fetch(:resource).dup end end def self.included(base) base.extend(ClassMethods) base.attr_reader(:resource) base.attribute(:ledger_id) base.attribute(:external_id) base.include(InstanceMethods) end end def initialize(*) raise NotImplementedError end def self.inherited(base) base.include(Mixin) super end end end
Version data entries
12 entries across 12 versions & 1 rubygems