Sha256: 42ccad8a9f360a0cd975ad0d88bdc4107f91a7fffde22b97d2f12f09ed10a04f

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 KB

Contents

=begin
  Camaleon CMS is a content management system
  Copyright (C) 2015 by Owen Peredo Diaz
  Email: owenperedo@gmail.com
  This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the  GNU Affero General Public License (GPLv3) for more details.
=end
class Widget::Assigned < PostDefault
  default_scope ->{ where(post_class: self.name).order(:comment_count) }
  # post_parent: sidebar_id
  # visibility: widget_id
  # comment_count: item_order
  alias_attribute :widget_id, :visibility
  alias_attribute :sidebar_id, :post_parent
  alias_attribute :item_order, :comment_count

  attr_accessible :widget_id, :sidebar_id, :item_order

  has_many :metas, ->{ where(object_class: 'Widget::Assigned')}, :class_name => "Meta", foreign_key: :objectid, dependent: :destroy
  belongs_to :sidebar, class_name: "Widget::Sidebar", foreign_key: :post_parent
  belongs_to :widget, class_name: "Widget::Main", foreign_key: :visibility
  after_initialize :fix_slug2
  before_create :set_order

  def fix_slug2
    self.slug = "slug_assigned" unless self.slug.present?
  end

  private
  def set_order
    self.item_order = self.sidebar.assigned.count + 1
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
camaleon_cms-0.2.1 app/models/widget/assigned.rb
camaleon_cms-0.2.0 app/models/widget/assigned.rb
camaleon_cms-0.1.9 app/models/widget/assigned.rb
camaleon_cms-0.1.8 app/models/widget/assigned.rb
camaleon_cms-0.1.7 app/models/widget/assigned.rb
camaleon_cms-0.1.6 app/models/widget/assigned.rb
camaleon_cms-0.1.5 app/models/widget/assigned.rb
camaleon_cms-0.1.4 app/models/widget/assigned.rb
camaleon_cms-0.1.3 app/models/widget/assigned.rb
camaleon_cms-0.1.2 app/models/widget/assigned.rb
camaleon_cms-0.0.2 app/models/widget/assigned.rb
camaleon_cms-0.0.1 app/models/widget/assigned.rb