OSDN Git Service

temp
[pettanr/pettanr.git] / lib / content.rb
1 class Pettanr::Content < Pettanr::Item
2   self.abstract_class = true
3   # ClassMethods
4   
5   def self.owner_type
6     :author
7   end
8   
9   def self.operator operators
10     case self.owner_type
11     when :author
12       operators.author
13     when :artist
14       operators.artist
15     else
16       nil
17     end
18   end
19   
20   def self.owner_column
21     self.owner_type.to_s + '_id'
22   end
23   
24   def self.edit content_id, operators
25     content = self.find content_id, self.show_opt
26     raise ActiveRecord::Forbidden unless content.own?(operators)
27     content
28   end
29   
30   #InstanceMethods
31   
32   def owner_model
33     self
34   end
35   
36   def visible? operators
37     super
38     return true if owner_model.own?(operators)
39     true
40   end
41   
42   def own? operators
43     operator = self.class.operator operators
44     return false unless operator
45     owner_model.attributes[self.class.self.class.owner_column] == operator.id
46   end
47   
48 end
49