Sha256: ef99f13f06477d73a098f30a846f4457544903cc457c1c86babe877f38e62005

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require 'crimp'

module Alephant
  module Publisher
    class Writer
      attr_reader :mapper, :cache

      def initialize(opts)
        @renderer_id =
          opts[:renderer_id]
        @cache = Cache.new(
          opts[:s3_bucket_id],
          opts[:s3_object_path]
        )
        @mapper = RenderMapper.new(
          opts[:renderer_id],
          opts[:view_path]
        )
        @lookup_table_name =
          opts[:lookup_table_name]
      end

      def write(data, version = nil)
        mapper.generate(data).each do |id, r|
          store(id, r.render, data[:options], version)
        end
      end

      private
      def store(id, content, options, version)
        location = location_for(
          id,
          Crimp.signature(options),
          version
        )

        cache.put(location, content)
        lookup(id).write(options, location)
      end

      def lookup(component_id)
        Lookup.create(@lookup_table_name, component_id)
      end

      def location_for(component_id, options_hash, version = nil)
        base_name = "#{@renderer_id}/#{component_id}/#{options_hash}"
        version ? "#{base_name}/#{version}" : base_name
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alephant-publisher-0.0.2 lib/alephant/publisher/models/writer.rb
alephant-publisher-0.0.1 lib/alephant/publisher/models/writer.rb