Module: Resizing::CarrierWave

Defined in:
lib/resizing/carrier_wave.rb,
lib/resizing/carrier_wave/storage/file.rb,
lib/resizing/carrier_wave/storage/remote.rb

Defined Under Namespace

Modules: ClassMethods, Storage Classes: Railtie

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



23
24
25
26
# File 'lib/resizing/carrier_wave.rb', line 23

def self.included(base)
  base.storage Resizing::CarrierWave::Storage::Remote
  base.extend ClassMethods
end

Instance Method Details

#build_urlObject



59
60
61
# File 'lib/resizing/carrier_wave.rb', line 59

def build_url
  "#{Resizing.configure.image_host}#{model.read_attribute(serialization_column)}"
end

#cache!(new_file) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/resizing/carrier_wave.rb', line 95

def cache!(new_file)
  return if new_file.nil?

  file = storage.store!(new_file)
  # do not assign @cache_id, bacause resizing do not support cache
  # save to resizing directly
  # @cache_id = file.public_id

  @filename = file.public_id.to_s
  @file = file
end

#default_formatObject



140
141
142
# File 'lib/resizing/carrier_wave.rb', line 140

def default_format
  @default_format
end

#default_urlObject

need override this. if you want to return some url when target_column is nil



64
65
66
# File 'lib/resizing/carrier_wave.rb', line 64

def default_url
  nil
end

#fileObject



34
35
36
37
38
39
40
41
# File 'lib/resizing/carrier_wave.rb', line 34

def file
  return if identifier.nil?
  return @file unless defined? @file

  @file ||= Resizing::CarrierWave::Storage::File.new(self)
  @file.retrieve(identifier)
  @file
end

#filenameObject



107
108
109
# File 'lib/resizing/carrier_wave.rb', line 107

def filename
  read_column
end

#formatObject



144
145
146
# File 'lib/resizing/carrier_wave.rb', line 144

def format
  requested_format || default_format
end

#initialize(*args) ⇒ Object



28
29
30
31
32
# File 'lib/resizing/carrier_wave.rb', line 28

def initialize(*args)
  @requested_format = nil
  @default_format = nil
  super
end

#read_columnObject



55
56
57
# File 'lib/resizing/carrier_wave.rb', line 55

def read_column
  model.read_attribute(serialization_column)
end

#remove_versions!(*args) ⇒ Object

store_versions! is called after delete Disable on Resizing, because transform the image when browser fetch the image URL github.com/carrierwaveuploader/carrierwave/blob/28190e99299a6131c0424a5d10205f471e39f3cd/lib/carrierwave/uploader/versions.rb#L18



130
131
132
# File 'lib/resizing/carrier_wave.rb', line 130

def remove_versions!(*args)
  # NOP
end

#renameObject

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/resizing/carrier_wave.rb', line 76

def rename
  raise NotImplementedError, 'rename is not implemented'
end

#requested_formatObject



134
135
136
137
138
# File 'lib/resizing/carrier_wave.rb', line 134

def requested_format
  # TODO
  # The request with uploading format parameter is not working on the Resizing until 2020/09/25
  @requested_format
end

#resize_to_fill(*args) ⇒ Object



85
86
87
88
# File 'lib/resizing/carrier_wave.rb', line 85

def resize_to_fill(*args)
  @transform ||= []
  @transform.push(:resize_to_fill, *args)
end

#resize_to_fit(*args) ⇒ Object



90
91
92
93
# File 'lib/resizing/carrier_wave.rb', line 90

def resize_to_fit(*args)
  @transform ||= []
  @transform.push(:resize_to_fit, *args)
end

#resize_to_limit(*args) ⇒ Object



80
81
82
83
# File 'lib/resizing/carrier_wave.rb', line 80

def resize_to_limit(*args)
  @transform ||= []
  @transform.push(:resize_to_limit, *args)
end

#serialization_columnObject



116
117
118
# File 'lib/resizing/carrier_wave.rb', line 116

def serialization_column
  model.send(:_mounter, mounted_as).send(:serialization_column)
end

#store!Object



111
112
113
114
# File 'lib/resizing/carrier_wave.rb', line 111

def store!
  # DO NOTHING
  super
end

#store_versions!(*args) ⇒ Object

store_versions! is called after store! Disable on Resizing, because transform the image when browser fetch the image URL github.com/carrierwaveuploader/carrierwave/blob/28190e99299a6131c0424a5d10205f471e39f3cd/lib/carrierwave/uploader/versions.rb#L18



123
124
125
# File 'lib/resizing/carrier_wave.rb', line 123

def store_versions!(*args)
  # NOP
end

#transform_stringObject



68
69
70
71
72
73
74
# File 'lib/resizing/carrier_wave.rb', line 68

def transform_string
  transforms = processors.map do |processor|
    transform_string_from processor
  end

  transforms.join('/')
end

#url(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/resizing/carrier_wave.rb', line 43

def url(*args)
  return default_url unless read_column.present?

  transforms = args.map do |version|
    version = version.intern
    raise "No version is found: #{version}, #{versions.keys} are exists." unless versions.has_key? version
    versions[version].transform_string
  end.compact

  "#{build_url}/#{transforms.join('/')}"
end