module Dynamoid::Paperclip::ClassMethods

Public Instance Methods

has_dynamoid_attached_file(field, options = {}) click to toggle source

Adds Dynamoid::Paperclip‘s “#has_dynamoid_attached_file” class method to the model which includes Paperclip and Paperclip::Glue in to the model. Additionally it’ll also add the required fields for Paperclip since DynamoDB is schemaless and doesn’t have migrations.

# File lib/dynamoid/paperclip.rb, line 41
def has_dynamoid_attached_file(field, options = {})

  ##
  # Include Paperclip and Paperclip::Glue for compatibility
  unless self.ancestors.include?(::Paperclip)
    include ::Paperclip
    include ::Paperclip::Glue
  end

  ##
  # Invoke Paperclip's #has_attached_file method and passes in the
  # arguments specified by the user that invoked Dynamoid::Paperclip#has_dynamoid_attached_file
  has_attached_file(field, options)

  ##
  # Define the necessary collection fields in Dynamoid for Paperclip
  field(:"#{field}_file_name")
  field(:"#{field}_content_type")
  field(:"#{field}_file_size", :integer)
  field(:"#{field}_updated_at", :datetime)
end