Sha256: c88e2b32176bc1f9b41c7526a66c01f77f8525ff8f1591a925e2ef972ddbf0f1

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

module MR; end
module MR::ReadModel

  module Data

    # `MR::ReadModel::Data` is a mixin that provides helpers for setting and
    # accessing the "data" for a read model. These methods provide a strict
    # interface to avoid confusing errors and ensure that the data for a
    # read model should, as much as possible, work.
    #
    # * Use the `read_model_data` protected method to access the data object.
    # * Use the `set_read_model_data` private method to write a data object.

    protected

    def read_model_data
      @read_model_data || raise(NoDataError.new(caller))
    end

    private

    def set_read_model_data(data)
      raise InvalidDataError unless data.respond_to?(:[])
      @read_model_data = data
    end

  end

  InvalidDataError = Class.new(ArgumentError)

  class NoDataError < RuntimeError
    def initialize(called_from = nil)
      super "the read model's data hasn't been set"
      set_backtrace(called_from) if called_from
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mr-0.35.2 lib/mr/read_model/data.rb