Sha256: 7529870a235cb6f3140f8d0e110fb82f4058e5645ecb6f2d77dfe504131ab691

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'crimp'

require 'alephant/sequencer'
require 'alephant/support/parser'

module Alephant
  module Publisher
    class WriteOperation
      attr_reader :msg, :data, :options, :options_hash, :version, :batch_sequencer

      def initialize(msg, opts)
        @msg                = msg
        @data               = Support::Parser.new(opts[:msg_vary_path]).parse(msg)
        @options            = @data[:options]
        @options_hash       = Crimp.signature(@options)
        @renderer_id        = opts[:renderer_id]
        @sequencer_opts     = opts[:sequencer_opts]
        @batch_sequencer    = sequencer_for(@renderer_id, @options)
        @version            = @batch_sequencer.sequence_id_from(@msg)
      end

      def sequencer_for(id, options)
        Sequencer.create(
          @sequencer_opts[:table_name],
          sequencer_id_from(id, options),
          @sequencer_opts[:id_path]
        )
      end

      private

      def sequencer_id_from(id,options)
        "#{id}/#{Crimp.signature(options)}"
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-publisher-0.1.3 lib/alephant/publisher/models/write_operation.rb