Sha256: cbe84bbad3910c4976ad335acfff277ddb9926314121f1d0d2412d21ac6b344a

Contents?: true

Size: 430 Bytes

Versions: 1

Compression:

Stored size: 430 Bytes

Contents

require "delegate"

class BelongsToAssociationProxy < SimpleDelegator
  def initialize(object_loader)
    @object_loader = object_loader
    @loaded = false
  end

  def method_missing(method_id, *args, &block)
    __load_object__

    super
  end

  def __getobj__
    __load_object__
    super
  end

  private

  def __load_object__
    __setobj__(@object_loader.call).tap {
      @loaded = true
    } unless @loaded
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sequel_mapper-0.0.1 lib/sequel_mapper/belongs_to_association_proxy.rb