Class: ExportedCatalogItemImage
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ExportedCatalogItemImage
- 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
-
#background_color ⇒ Object
Alias for Exported_catalog_item_packet#background_color.
-
#exported_catalog_item_packet ⇒ Object
Alias for Exported_catalog_item#exported_catalog_item_packet.
-
#image_format ⇒ Object
Alias for Exported_catalog_item_packet#image_format.
-
#image_height_lteq ⇒ Object
Alias for Exported_catalog_item_packet#image_height_lteq.
-
#image_width_lteq ⇒ Object
Alias for Exported_catalog_item_packet#image_width_lteq.
-
#item ⇒ Object
Alias for Exported_catalog_item#item.
-
#named_transformation ⇒ Object
Alias for Exported_catalog_item_packet#named_transformation.
-
#transformation_position ⇒ Object
Alias for Exported_catalog_item_packet#transformation_position.
Instance Method Summary collapse
- #download(directory_path) ⇒ Object
- #file_extension ⇒ Object
- #file_name ⇒ Object
- #file_name_without_extension ⇒ Object
- #image_thumbnail_url ⇒ Object
- #image_url(download: false) ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Method Details
#background_color ⇒ Object
Alias for Exported_catalog_item_packet#background_color
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_item ⇒ ExportedCatalogItem
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_packet ⇒ Object
Alias for Exported_catalog_item#exported_catalog_item_packet
28 |
# File 'app/models/exported_catalog_item_image.rb', line 28 delegate :exported_catalog_item_packet, to: :exported_catalog_item |
#file_extension ⇒ Object
52 53 54 |
# File 'app/models/exported_catalog_item_image.rb', line 52 def file_extension image_format.presence || image&..presence || "jpeg" end |
#file_name ⇒ Object
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_extension ⇒ Object
60 61 62 |
# File 'app/models/exported_catalog_item_image.rb', line 60 def file_name_without_extension base_file_name end |
#image ⇒ Image
25 |
# File 'app/models/exported_catalog_item_image.rb', line 25 belongs_to :image, optional: true |
#image_format ⇒ Object
Alias for Exported_catalog_item_packet#image_format
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_lteq ⇒ Object
Alias for Exported_catalog_item_packet#image_height_lteq
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_url ⇒ Object
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_lteq ⇒ Object
Alias for Exported_catalog_item_packet#image_width_lteq
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 |
#item ⇒ Object
Alias for Exported_catalog_item#item
27 |
# File 'app/models/exported_catalog_item_image.rb', line 27 delegate :item, to: :exported_catalog_item |
#named_transformation ⇒ Object
Alias for Exported_catalog_item_packet#named_transformation
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_position ⇒ Object
Alias for Exported_catalog_item_packet#transformation_position
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 |