Sha256: e6f719fe50ab48c2a9e2ef6f9cf07c2ec72182e3f7da266df391481f2b474d61

Contents?: true

Size: 758 Bytes

Versions: 2

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true

module Paperweight
  # The location of the attachment in terms of paths are URLs.
  class Location
    attr_reader :model, :style

    def initialize(model, style = :original)
      @model = model
      @style = style
    end

    def path
      "#{table_name}/#{model.id}-#{style}-#{model.image_uuid}"
    end

    def url
      "#{self.class.prefix}/#{path}"
    end

    def default_url
      "#{self.class.prefix}/#{table_name}/#{style}.gif"
    end

    def self.prefix
      @prefix ||=
        if Rails.env.production?
          Paperweight.config.asset_server
        else
          'http://localhost:3000/paperweight'
        end
    end

    private

    def table_name
      model.class.table_name
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paperweight-0.0.4 lib/paperweight/location.rb
paperweight-0.0.3 lib/paperweight/location.rb