Class: ExportedCatalogItemPacketImageAttribute

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/exported_catalog_item_packet_image_attribute.rb

Overview

== Schema Information

Table name: exported_catalog_item_packet_image_attributes
Database name: primary

id :integer not null, primary key
image_source :string default("website")
mode :string default("profile")
quantity :integer default(20)
selected :boolean default(FALSE)
tag :string
created_at :datetime not null
updated_at :datetime not null
exported_catalog_item_packet_id :integer

Indexes

ecip_id_selected (exported_catalog_item_packet_id,selected)

Constant Summary collapse

MODES =
%w[profile tag].freeze
CORE_TAGS =
%w[main product_shot lifestyle].map { |s| s.parameterize.dasherize.capitalize }.freeze
IMAGE_SOURCES =
%w[website amazon walmart].freeze

Instance Attribute Summary collapse

Belongs to 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 Attribute Details

#image_sourceObject (readonly)



32
# File 'app/models/exported_catalog_item_packet_image_attribute.rb', line 32

validates :image_source, inclusion: { in: IMAGE_SOURCES }, allow_blank: true

#modeObject (readonly)



31
# File 'app/models/exported_catalog_item_packet_image_attribute.rb', line 31

validates :mode, inclusion: { in: MODES }

Instance Method Details

#exported_catalog_item_packetExportedCatalogItemPacket



21
# File 'app/models/exported_catalog_item_packet_image_attribute.rb', line 21

belongs_to :exported_catalog_item_packet, inverse_of: :exported_catalog_item_packet_image_attributes, optional: true

#profile_mode?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/exported_catalog_item_packet_image_attribute.rb', line 34

def profile_mode?
  mode == "profile"
end

#retrieve_images(item) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'app/models/exported_catalog_item_packet_image_attribute.rb', line 42

def retrieve_images(item)
  images = if profile_mode?
             retrieve_by_profile(item)
           else
             retrieve_by_tag(item)
           end

  OpenStruct.new(all_images: images)
end

#tag_mode?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/exported_catalog_item_packet_image_attribute.rb', line 38

def tag_mode?
  mode == "tag"
end