Sha256: 74b8817c1dd3bdd125e8804bcdfc1b1cc12764fc57b0bc916a9e57c9d39f25ea

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

class Shelf < ActiveRecord::Base
  attr_accessible :name, :display_name, :note, :library_id, :closed
  include MasterModel
  scope :real, where('library_id != 1')
  belongs_to :library, :validate => true
  has_many :items, :include => [:circulation_status]
  has_many :picture_files, :as => :picture_attachable, :dependent => :destroy

  validates_associated :library
  validates_presence_of :library
  validates_uniqueness_of :display_name, :scope => :library_id
  validates :name, :format => {:with => /^[a-z][0-9a-z\-_]{1,254}$/}

  acts_as_list :scope => :library

  searchable do
    string :name
    string :library do
      library.name
    end
    text :name do
      [name, library.name, display_name, library.display_name]
    end
    integer :position
  end

  paginates_per 10

  def web_shelf?
    return true if self.id == 1
    false
  end

  def self.web
    Shelf.find(1)
  end

  def first?
    # 必ずposition順に並んでいる
    return true if library.shelves.first.position == position
    false
  end

  def localized_display_name
    display_name.localize
  end
end

# == Schema Information
#
# Table name: shelves
#
#  id           :integer         not null, primary key
#  name         :string(255)     not null
#  display_name :text
#  note         :text
#  library_id   :integer         default(1), not null
#  items_count  :integer         default(0), not null
#  position     :integer
#  created_at   :datetime        not null
#  updated_at   :datetime        not null
#  deleted_at   :datetime
#  closed       :boolean         default(FALSE), not null
#

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
enju_library-0.1.0.pre5 app/models/shelf.rb
enju_library-0.1.0.pre4 app/models/shelf.rb
enju_library-0.1.0.pre3 app/models/shelf.rb
enju_library-0.1.0.pre2 app/models/shelf.rb
enju_library-0.1.0.pre app/models/shelf.rb