Module: ThecoreSettings::Uploads

Included in:
Setting
Defined in:
lib/thecore_settings/uploads.rb,
lib/thecore_settings/storage/shrine_uploader.rb,
lib/thecore_settings/storage/carrier_wave_uploader.rb

Defined Under Namespace

Classes: CarrierWaveUploader, ShrineUploader

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/thecore_settings/uploads.rb', line 14

def self.included(base)
  # carrierwave
  if base.respond_to?(:mount_uploader)
    # puts "[thecore_settings] CarrierWave detected"
    # base.field(:file, type: String)
    base.mount_uploader(:file, ThecoreSettings::Uploads::CarrierWaveUploader)
    Settings.file_uploads_supported = true
    Settings.file_uploads_engine = :carrierwave
  # mongoid-paperclip
  elsif ThecoreSettings.mongoid? && ::Mongoid.const_defined?('Paperclip')
    base.send(:include, ::Mongoid::Paperclip)
    # puts "[thecore_settings] PaperClip detected"
    base.field(:file, type: String)
    base.has_mongoid_attached_file(:file, self.paperclip_options)
    if base.respond_to?(:do_not_validate_attachment_file_type)
      base.do_not_validate_attachment_file_type :file
    end

    Settings.file_uploads_supported = true
    Settings.file_uploads_engine = :paperclip
  elsif ThecoreSettings.active_record? && defined?(Paperclip)
    base.has_attached_file(:file, self.paperclip_options)
    if base.respond_to?(:do_not_validate_attachment_file_type)
      base.do_not_validate_attachment_file_type :file
    end
    Settings.file_uploads_supported = true
    Settings.file_uploads_engine = :paperclip
  elsif ThecoreSettings.active_record? && defined?(Shrine)
    Settings.file_uploads_supported = true
    Settings.file_uploads_engine = :shrine
    base.send(:include, ShrineUploader::Attachment(:file))
  elsif ThecoreSettings.mongoid? && ::Mongoid.const_defined?('Shrine')
    base.send(:include, ::Mongoid::Document)
    base.send(:include, ShrineUploader::Attachment(:file))
    base.field(:file_data, type: String)
    Settings.file_uploads_supported = true
    Settings.file_uploads_engine = :shrine
  else
    # puts "[thecore_settings] Uploads disabled"
  end
end

.paperclip_optionsObject



6
7
8
9
10
11
12
# File 'lib/thecore_settings/uploads.rb', line 6

def self.paperclip_options
  if defined?(Rails)
    {}
  else
    {path: "#{File.dirname(__FILE__)}/../../uploads/:filename", url: '/uploads/:filename'}
  end
end