Class: PinboardItem

Inherits:
ApplicationRecord show all
Includes:
Housekeeping
Defined in:
app/models/pinboard_item.rb

Overview

A PinboardItem is an object on a user's pinboard.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (Integer) inserted_count

Returns (not implemented) - the number of times this item has been inserted

Returns:

  • (Integer)

    (not implemented) - the number of times this item has been inserted



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

- (Boolean) is_cross_project

Returns pinboard item will show up regardless of which project is selected

Returns:

  • (Boolean)

    pinboard item will show up regardless of which project is selected



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

- (Boolean) is_inserted

Returns when true this pinboard item is automatically inserted into accepting form fields

Returns:

  • (Boolean)

    when true this pinboard item is automatically inserted into accepting form fields



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

- (Integer) pinned_object_id

Returns the id of the object being pinned

Returns:

  • (Integer)

    the id of the object being pinned



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

- (String) pinned_object_type

Returns the type of the object being pinned

Returns:

  • (String)

    the type of the object being pinned



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

- (Integer) position

Returns the relative position of this object, nests within object type

Returns:

  • (Integer)

    the relative position of this object, nests within object type



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

- (Integer) user_id

Returns this identifies the pinboard

Returns:

  • (Integer)

    this identifies the pinboard



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/pinboard_item.rb', line 35

class PinboardItem < ApplicationRecord
  include Housekeeping

  acts_as_list scope: [:project_id, :pinned_object_type]

  belongs_to :user
  belongs_to :pinned_object, polymorphic: true

  before_validation  :validate_is_cross_project
  validates_presence_of :user_id, :pinned_object_id, :pinned_object_type
  validates_uniqueness_of :user_id, scope: [ :pinned_object_id, :pinned_object_type ]

  after_save :update_insertable

  scope :for_object, -> (object) {where(pinned_object_id: object.id, pinned_object_type: object.class.to_s) }

  def self.reorder(pinboard_item_ids)
    pinboard_item_ids.each_with_index do |id, i|
      PinboardItem.find(id).update_attribute(:position, i)
    end
  end

  def is_inserted?
    !is_inserted.blank?
  end

  def is_cross_project?
    !is_cross_project.blank?
  end

  def set_as_insertable
    PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
      p.update_column(:is_inserted, false)
    end
  end

  protected

  def update_insertable
    if is_inserted?
      set_as_insertable
    end
  end

  def validate_is_cross_project
    errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
  end

end

Class Method Details

+ (Object) reorder(pinboard_item_ids)



51
52
53
54
55
# File 'app/models/pinboard_item.rb', line 51

def self.reorder(pinboard_item_ids)
  pinboard_item_ids.each_with_index do |id, i|
    PinboardItem.find(id).update_attribute(:position, i)
  end
end

Instance Method Details

- (Boolean) is_cross_project?

Returns:

  • (Boolean)


61
62
63
# File 'app/models/pinboard_item.rb', line 61

def is_cross_project?
  !is_cross_project.blank?
end

- (Boolean) is_inserted?

Returns:

  • (Boolean)


57
58
59
# File 'app/models/pinboard_item.rb', line 57

def is_inserted?
  !is_inserted.blank?
end

- (Object) set_as_insertable



65
66
67
68
69
# File 'app/models/pinboard_item.rb', line 65

def set_as_insertable
  PinboardItem.where(project_id: project_id, pinned_object_type: pinned_object_type).where.not(id: id).find_each do |p|
    p.update_column(:is_inserted, false)
  end
end

- (Object) update_insertable (protected)



73
74
75
76
77
# File 'app/models/pinboard_item.rb', line 73

def update_insertable
  if is_inserted?
    set_as_insertable
  end
end

- (Object) validate_is_cross_project (protected)



79
80
81
# File 'app/models/pinboard_item.rb', line 79

def validate_is_cross_project
  errors.add(:is_cross_project, 'model is not a cross project model') if is_cross_project? && !pinned_object.class.ancestors.map(&:name).include?('Shared::SharedAcrossProjects')
end