Sha256: 9b6b5c111b4402f8e60633c45d3cb9231803d8d5784e2f1b062bc839b5751100

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 'gecko/record/base'

module Gecko
  module Record
    class Image < Base
      AVAILABLE_SIZES = [:full, :thumbnail]

      belongs_to :variant
      belongs_to :uploader, class_name: "User"
      attribute :name,             String
      attribute :url,              String
      attribute :position,         Integer
      attribute :base_path,        String,        readonly: true
      attribute :file_name,        String,        readonly: true
      attribute :versions,         Array[String], readonly: true

      # attribute :image_processing, Boolean

      # URL for image
      #
      # @param [Symbol] :size (:full) The image size, currently only :full,
      #  :medium and :thumbnail supported
      #
      # @return [String]
      #
      # @api public
      def url(size = :full)
        super() || build_url(size)
      end

    private

      def build_url(size)
        if size == :full
          file_path = file_name
        else
          file_path = "#{size}_#{file_name}"
        end
        [base_path, file_path].join("/")
      end
    end

    class ImageAdapter < BaseAdapter
    private

      def update_record(_record)
        raise NotImplementedError
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gecko-ruby-0.0.10 lib/gecko/record/image.rb
gecko-ruby-0.0.9 lib/gecko/record/image.rb
gecko-ruby-0.0.8 lib/gecko/record/image.rb