Class: ExclusiveItemGroup

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

Overview

== Schema Information

Table name: exclusive_item_groups
Database name: primary

id :integer not null, primary key
description :string
key :string
name :string
per_thermostat :boolean default(FALSE), not null
position :integer
title :string

Indexes

index_exclusive_item_groups_on_key (key)

Constant Summary

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#descriptionString (readonly)

Returns:

  • (String)


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

validates :description, presence: true

#keyString (readonly)

Returns:

  • (String)


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

validates :key, uniqueness: true, presence: true

#nameString (readonly)

Returns:

  • (String)


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

validates :name, presence: true

#positionInteger (readonly)

Returns:

  • (Integer)


26
# File 'app/models/exclusive_item_group.rb', line 26

validates :position, uniqueness: true, presence: true

#titleString (readonly)

Returns:

  • (String)


30
# File 'app/models/exclusive_item_group.rb', line 30

validates :title, presence: true

Class Method Details

.options_for_selectArray<Array<String, Integer>>

Returns:

  • (Array<Array<String, Integer>>)


35
36
37
# File 'app/models/exclusive_item_group.rb', line 35

def self.options_for_select
  ExclusiveItemGroup.order(:position).pluck(:name, :id)
end

Instance Method Details

#compact_positionsvoid

This method returns an undefined value.



45
46
47
48
49
# File 'app/models/exclusive_item_group.rb', line 45

def compact_positions
  order(:position).each_with_index do |o, i|
    o.update_column(:position, i)
  end
end

#itemsActiveRecord::Relation<Item>

Returns:

  • (ActiveRecord::Relation<Item>)


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

has_many :items, -> { order(:sku) }, inverse_of: :exclusive_item_group, dependent: :nullify

#next_positionInteger

Returns:

  • (Integer)


40
41
42
# File 'app/models/exclusive_item_group.rb', line 40

def next_position
  (maximum(:position) || 0) + 1
end

#ok_to_delete?Boolean

Returns:

  • (Boolean)


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

def ok_to_delete?
  items.empty?
end