1 class StorySheet < Peta::Leaf
6 validates :story_id, :presence => true, :numericality => true, :existence => {:both => false}
7 validates :sheet_id, :presence => true, :numericality => true, :existence => {:both => false}
8 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
10 scope :with_story, -> do
14 scope :find_index, -> do
15 with_story.where(Story.arel_table[:visible].gt 0).references(:story)
18 scope :find_private, -> (operators) do
19 with_story.where(Story.arel_table[:author_id].eq operators.author.id).references(:story)
22 scope :by_story, -> (story_id) do
23 where(story_id: story_id)
26 scope :find_by_story, -> (story_id) do
27 find_index.by_story(story_id)
30 scope :find_by_sheet, -> (sheet_id) do
31 find_index.where(sheet_id: sheet_id).references(:story)
34 scope :find_by_author, -> (author_id) do
35 find_index.where(Story.arel_table[:author_id].eq author_id).references(:story)
38 scope :find_play, -> (story_id) do
39 find_by_story(story_id)
42 scope :find_private_play, -> (story_id, operators) do
43 find_private(operators).by_story(story_id)
52 def overwrite operators
55 def self.public_list_where list
59 def self.by_author_list_includes
77 return nil if self.story_id == nil or self.sheet_id == nil
78 self.story.own?(operators) and self.sheet.usable?(operators)