OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / models / comic.rb
index 86c28e5..269f07b 100644 (file)
@@ -1,5 +1,5 @@
 #コミック
-class Comic < Peta::Content
+class Comic < Peta::Binder
   load_manifest
   has_many :comic_stories
   belongs_to :author
@@ -8,12 +8,39 @@ class Comic < Peta::Content
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
   
-  def self.visible_count_options
-    {:conditions => 'visible > 0'}
+  scope :find_index, -> do
+    where(arel_table[:visible].gt 0)
+  end
+  
+  scope :find_private, -> (operators) do 
+    where(author_id: operators.author.id)
+  end
+  
+  scope :find_by_author, -> (author_id) do 
+    find_index.where(author_id: author_id)
+  end
+  
+  scope :with_stories, -> do
+    includes(comic_stories: :story)
+  end
+  
+  scope :find_by_story, -> (story_id) do 
+    with_stories.find_index.where(Story.arel_table[:id].eq story_id).references(:story)
+  end
+  
+  # scope of find_play
+  def self.find_play(id)
+    ComicStory.find_play(id)
+  end
+  
+  # scope of find_private_play
+  def self.find_private_play(id, operators)
+    ComicStory.find_private_play(id, operators)
   end
   
   def supply_default
     self.visible = 0 if self.visible.blank?
+    self.author_id = nil
   end
   
   def overwrite operators
@@ -35,47 +62,14 @@ class Comic < Peta::Content
   def symbol_filename
   end
   
-  def self.public_list_where
+  def self.public_list_where list
     'comics.visible > 0'
   end
   
-  def self.list_order
-    'comics.updated_at desc'
-  end
-  
-  def self.list_opt
-    {:comic_stories => {:story => {}}, :author => {} }
-  end
-  
-  def self.list_json_opt
-    {:include => {:comic_stories => {:include => {:story => {}}}, :author => {}}}
-  end
-  
   def self.show_opt
     {:include => {:comic_stories => {:story => {}}, :author => {}}}
   end
   
-  def self.show_json_opt
-    {:include => {:comic_stories => {:include => {:story => {}}}, :author => {}}}
-  end
-  
-  def tag_attributes column = nil, opt = {}
-    {
-    }
-  end
-  
-  def destroy_with_story
-    res = false
-    Comic.transaction do
-      self.stories.each do |story|
-        raise ActiveRecord::Rollback unless story.destroy_and_shorten
-      end
-      raise ActiveRecord::Rollback unless self.destroy
-      res = true
-    end
-    res
-  end
-  
   def scenario
     panels.map {|panel|
       panel.scenario