2 class Comic < Peta::Binder
4 has_many :comic_stories
7 validates :title, :presence => true, :length => {:maximum => 100}
8 validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
9 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
11 scope :find_index, -> do
12 where(arel_table[:visible].gt 0)
15 scope :find_private, -> (operators) do
16 where(author_id: operators.author.id)
19 scope :find_by_author, -> (author_id) do
20 find_index.where(author_id: author_id)
23 scope :with_stories, -> do
24 includes(comic_stories: :story)
27 scope :find_by_story, -> (story_id) do
28 with_stories.find_index.where(Story.arel_table[:id].eq story_id).references(:story)
32 def self.find_play(id)
33 ComicStory.find_play(id)
36 # scope of find_private_play
37 def self.find_private_play(id, operators)
38 ComicStory.find_private_play(id, operators)
42 self.visible = 0 if self.visible.blank?
46 def overwrite operators
47 return false unless operators.author
48 self.author_id = operators.author.id
51 def visible? operators
53 when nil # super return
65 def self.public_list_where list
70 {:include => {:comic_stories => {:story => {}}, :author => {}}}