Class: Para::ModelFieldParsers::Paperclip

Inherits:
Base
  • Object
show all
Defined in:
lib/para/model_field_parsers/paperclip.rb

Instance Attribute Summary

Attributes inherited from Base

#fields_hash, #mappings, #model

Instance Method Summary collapse

Methods inherited from Base

#find_attributes_for_mapping, #initialize, register

Constructor Details

This class inherits a constructor from Para::ModelFieldParsers::Base

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/para/model_field_parsers/paperclip.rb', line 25

def applicable?
  model.respond_to?(:attachment_definitions)
end

#parse!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/para/model_field_parsers/paperclip.rb', line 6

def parse!
  model.attachment_definitions.each do |key, options|
    paperclip_suffixes.each do |suffix|
      field_name = [key, suffix].join('_').to_sym
      @fields_hash.delete(field_name)
    end

    @fields_hash[key] = if image?(options)
      AttributeField::ImageField.new(
        model, name: key, type: 'image', field_type: 'image'
      )
    else
      AttributeField::FileField.new(
        model, name: key, type: 'file', field_type: 'file'
      )
    end
  end
end