Class: ExportedCatalogItemImage

Inherits:
ApplicationRecord show all
Defined in:
app/models/exported_catalog_item_image.rb

Overview

== Schema Information

Table name: exported_catalog_item_images
Database name: primary

id :integer not null, primary key
excluded :boolean default(FALSE)
format :string
tag :string
created_at :datetime not null
updated_at :datetime not null
exported_catalog_item_id :integer
image_id :integer

Indexes

index_exported_catalog_item_images_on_exported_catalog_item_id (exported_catalog_item_id)

Foreign Keys

fk_rails_... (exported_catalog_item_id => exported_catalog_items.id) ON DELETE => cascade

Belongs to collapse

Delegated Instance Attributes collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#background_colorObject

Alias for Exported_catalog_item_packet#background_color

Returns:

  • (Object)

    Exported_catalog_item_packet#background_color

See Also:



29
30
# File 'app/models/exported_catalog_item_image.rb', line 29

delegate :image_width_lteq, :image_height_lteq, :image_format, :transformation_position,
:named_transformation, :background_color, to: :exported_catalog_item_packet

#download(directory_path) ⇒ Object



64
65
66
67
68
69
70
# File 'app/models/exported_catalog_item_image.rb', line 64

def download(directory_path)
  tempfile = Down::Http.download(image_url(download: true)) { |client| client.timeout(read: 120) }
  file_path = "#{directory_path}/#{file_name}"
  puts "Final path: #{file_path}"
  FileUtils.mv tempfile.path, file_path
  { file_name: file_name, file_path: file_path }
end

#exported_catalog_itemExportedCatalogItem



24
# File 'app/models/exported_catalog_item_image.rb', line 24

belongs_to :exported_catalog_item, inverse_of: :exported_catalog_item_images, optional: true

#exported_catalog_item_packetObject

Alias for Exported_catalog_item#exported_catalog_item_packet

Returns:

  • (Object)

    Exported_catalog_item#exported_catalog_item_packet

See Also:



28
# File 'app/models/exported_catalog_item_image.rb', line 28

delegate :exported_catalog_item_packet, to: :exported_catalog_item

#file_extensionObject



52
53
54
# File 'app/models/exported_catalog_item_image.rb', line 52

def file_extension
  image_format.presence || image&.attachment_format.presence || "jpeg"
end

#file_nameObject



56
57
58
# File 'app/models/exported_catalog_item_image.rb', line 56

def file_name
  "#{base_file_name}.#{file_extension}"
end

#file_name_without_extensionObject



60
61
62
# File 'app/models/exported_catalog_item_image.rb', line 60

def file_name_without_extension
  base_file_name
end

#imageImage

Returns:

See Also:



25
# File 'app/models/exported_catalog_item_image.rb', line 25

belongs_to :image, optional: true

#image_formatObject

Alias for Exported_catalog_item_packet#image_format

Returns:

  • (Object)

    Exported_catalog_item_packet#image_format

See Also:



29
30
# File 'app/models/exported_catalog_item_image.rb', line 29

delegate :image_width_lteq, :image_height_lteq, :image_format, :transformation_position,
:named_transformation, :background_color, to: :exported_catalog_item_packet

#image_height_lteqObject

Alias for Exported_catalog_item_packet#image_height_lteq

Returns:

  • (Object)

    Exported_catalog_item_packet#image_height_lteq

See Also:



29
30
# File 'app/models/exported_catalog_item_image.rb', line 29

delegate :image_width_lteq, :image_height_lteq, :image_format, :transformation_position,
:named_transformation, :background_color, to: :exported_catalog_item_packet

#image_thumbnail_urlObject



48
49
50
# File 'app/models/exported_catalog_item_image.rb', line 48

def image_thumbnail_url
  image.image_url(size: '150x150', thumbnail: true, encode_format: image_format, transformation_position: 'path')
end

#image_url(download: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/exported_catalog_item_image.rb', line 32

def image_url(download: false)
  opts = { transformation_position: transformation_position }

  if named_transformation
    opts[:named] = named_transformation
  else
    opts[:width] = image_width_lteq
    opts[:height] = image_height_lteq
    opts[:encode_format] = image_format
  end
  opts[:background] = background_color if background_color.present?
  opts[:download] = true if download

  image.image_url(**opts.compact)
end

#image_width_lteqObject

Alias for Exported_catalog_item_packet#image_width_lteq

Returns:

  • (Object)

    Exported_catalog_item_packet#image_width_lteq

See Also:



29
30
# File 'app/models/exported_catalog_item_image.rb', line 29

delegate :image_width_lteq, :image_height_lteq, :image_format, :transformation_position,
:named_transformation, :background_color, to: :exported_catalog_item_packet

#itemObject

Alias for Exported_catalog_item#item

Returns:

  • (Object)

    Exported_catalog_item#item

See Also:



27
# File 'app/models/exported_catalog_item_image.rb', line 27

delegate :item, to: :exported_catalog_item

#named_transformationObject

Alias for Exported_catalog_item_packet#named_transformation

Returns:

  • (Object)

    Exported_catalog_item_packet#named_transformation

See Also:



29
30
# File 'app/models/exported_catalog_item_image.rb', line 29

delegate :image_width_lteq, :image_height_lteq, :image_format, :transformation_position,
:named_transformation, :background_color, to: :exported_catalog_item_packet

#transformation_positionObject

Alias for Exported_catalog_item_packet#transformation_position

Returns:

  • (Object)

    Exported_catalog_item_packet#transformation_position

See Also:



29
30
# File 'app/models/exported_catalog_item_image.rb', line 29

delegate :image_width_lteq, :image_height_lteq, :image_format, :transformation_position,
:named_transformation, :background_color, to: :exported_catalog_item_packet