1 class ComicStory < Peta::Leaf
7 validates :comic_id, :presence => true, :numericality => true, :existence => {:both => false}
8 validates :story_id, :presence => true, :numericality => true, :existence => {:both => false}
9 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
11 scope :with_comic, -> do
15 scope :find_index, -> do
16 with_comic.where(Comic.arel_table[:visible].gt 0).references(:comic)
19 scope :find_private, -> (operators) do
20 with_comic.where(Comic.arel_table[:author_id].eq operators.author.id).references(:comic)
23 scope :by_comic, -> (comic_id) do
24 where(comic_id: comic_id)
27 scope :find_by_comic, -> (comic_id) do
28 find_index.by_comic(comic_id)
31 scope :find_by_story, -> (story_id) do
32 find_index.where(story_id: story_id).references(:comic)
35 scope :find_by_author, -> (author_id) do
36 find_index.where(Comic.arel_table[:author_id].eq author_id).references(:comic)
39 scope :find_play, -> (comic_id) do
40 find_by_comic(comic_id)
43 scope :find_private_play, -> (comic_id, operators) do
44 find_private(operators).by_comic(comic_id)
53 def overwrite operators
61 I18n.t('comic_stories.show.t', :t => self.disp_t)
65 self.disp_t_by_text + ':' + self.story.title
68 def self.public_list_where list
72 def self.by_author_list_includes
89 return nil if self.story_id == nil or self.comic_id == nil
90 self.comic.own?(operators) and self.story.own?(operators)