OSDN Git Service

upgrade devise to 3
[pettanr/pettanr.git] / app / models / comic_story.rb
1 class ComicStory < Peta::Leaf
2   load_manifest
3   belongs_to :author
4   belongs_to :comic
5   belongs_to :story
6   
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}
10   
11   def supply_default
12     self.comic_id = nil
13     self.story_id = nil
14     self.t = nil
15   end
16   
17   def overwrite operators
18   end
19   
20   def disp_t
21     self.t + 1
22   end
23   
24   def disp_t_by_text
25     I18n.t('comic_stories.show.t', :t => self.disp_t)
26   end
27   
28   def title
29     self.disp_t_by_text + ':' + self.story.title
30   end
31   
32   def self.public_list_where list
33     'comics.visible > 0'
34   end
35   
36   def self.by_author_list_includes
37     {
38       :comic => {
39         :author => {}
40       }
41     }
42   end
43   
44   def self.show_opt
45     {:include => {
46       :comic => {
47         :author => {}
48       }
49     }}
50   end
51   
52   def allow? operators
53     return nil if self.story_id == nil or self.comic_id == nil
54     self.comic.own?(operators) and self.story.own?(operators)
55   end
56   
57 end