forked from chamnap/liquid-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poro.rb
58 lines (47 loc) · 1.29 KB
/
poro.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Model
include Liquid::Rails::Droppable
def initialize(hash={})
@attributes = hash
end
def id
@attributes[:id] || @attributes['id'] || object_id
end
def respond_to?(method, include_private=false)
return true if @attributes.key?(method)
super
end
def respond_to_missing?(method, include_private=false)
@attributes.key?(method) || super
end
def method_missing(meth, *args)
if meth.to_s =~ /^(.*)=$/
@attributes[$1.to_sym] = args[0]
elsif @attributes.key?(meth)
@attributes[meth]
else
super
end
end
end
class Profile < Model
end
class ProfileDrop < Liquid::Rails::Drop
attributes :name, :description
end
Post = Class.new(Model)
Comment = Class.new(Model)
PostDrop = Class.new(Liquid::Rails::Drop) do
attributes :title, :body, :id
has_many :comments
has_many :recomments, with: 'ReCommentDrop', class_name: 'CommentsDrop'
end
CommentDrop = Class.new(Liquid::Rails::Drop) do
attributes :id, :body
belongs_to :post
belongs_to :repost, class_name: 'RePostDrop'
end
ReProfileDrop = Class.new(Liquid::Rails::Drop)
PostsDrop = Class.new(Liquid::Rails::CollectionDrop)
RePostDrop = Class.new(Liquid::Rails::Drop)
ReCommentDrop = Class.new(Liquid::Rails::Drop)
CommentsDrop = Class.new(Liquid::Rails::CollectionDrop)