-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.rb
59 lines (49 loc) · 1.25 KB
/
models.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
59
require 'rubygems'
require 'mongo_mapper'
MongoMapper.database = 'mini-card'
class Tag
include MongoMapper::Document
key :key, String, :required => true, :unique => true
many :tag_card_lks, :order => 'created_at desc'
timestamps!
#throught あるっけ
def cards
tag_card_lks.map{|lk| lk.card }
end
end
class TagCardLk
include MongoMapper::Document
key :tag_id, ObjectId
key :card_id, ObjectId
timestamps!
belongs_to :tag
belongs_to :card
end
class Card
include MongoMapper::Document
key :title, String, :unique => true
key :text, String, :required => true
many :tag_card_lks
timestamps!
def r_text
taged_text = text.gsub(/(#[^\s\n]+)/){ "<a href='/cards/tagged/#{$1[1..-1]}'>#{$1}</a>" }
taged_text.gsub(/\[([^\[\]]+)\]/){ "<a href='/cards/title/#{$1}'>#{$1}</a>" }
end
# def link_cards
# Link.all(:from_id => self._id, :order => "no").map{|lk| lk.to }
# end
#
# def linked_cards
# Link.all(:to_id => self._id, :order => "no").map{|lk| lk.from }
# end
end
# class Link
# include MongoMapper::Document
# key :no, Integer
# key :from_id, ObjectId
# key :to_id, ObjectId
# timestamps!
#
# belongs_to :from, :class_name => 'Card'
# belongs_to :to, :class_name => 'Card'
# end