Module: Dynamoid::Paperclip::ClassMethods

Defined in:
lib/dynamoid/paperclip.rb

Instance Method Summary collapse

Instance Method Details

#has_dynamoid_attached_file(field, options = {}) ⇒ Object

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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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