Class: MongoDocument
- Inherits:
-
Object
- Object
- MongoDocument
- Defined in:
- lib/models/mongo_document.rb
Instance Attribute Summary collapse
-
#is_new ⇒ Object
Returns the value of attribute is_new.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #[]=(index, value) ⇒ Object
- #date_created ⇒ Object
- #doc_link ⇒ Object
- #hidden ⇒ Object
- #id ⇒ Object
- #id=(value) ⇒ Object
-
#initialize(doc, collection, id = nil, modified_time = nil) ⇒ MongoDocument
constructor
A new instance of MongoDocument.
- #last_modified ⇒ Object
- #raw_document ⇒ Object
- #ref ⇒ Object
- #ref=(value) ⇒ Object
- #standardised_document ⇒ Object
- #stripped_document ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(doc, collection, id = nil, modified_time = nil) ⇒ MongoDocument
Returns a new instance of MongoDocument.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/models/mongo_document.rb', line 6 def initialize doc, collection, id=nil, modified_time=nil @doc = doc @collection = collection if !(id == nil) @doc['_id'] = id end if !(modified_time==nil) @doc['_koda_last_modified']=modified_time end end |
Instance Attribute Details
#is_new ⇒ Object
Returns the value of attribute is_new.
4 5 6 |
# File 'lib/models/mongo_document.rb', line 4 def is_new @is_new end |
Instance Method Details
#[](index) ⇒ Object
41 42 43 |
# File 'lib/models/mongo_document.rb', line 41 def [](index) @doc[index] end |
#[]=(index, value) ⇒ Object
37 38 39 |
# File 'lib/models/mongo_document.rb', line 37 def []=(index, value) @doc[index] = value end |
#date_created ⇒ Object
68 69 70 71 |
# File 'lib/models/mongo_document.rb', line 68 def date_created return @doc['datecreated'] if(@doc['datecreated']) '' end |
#doc_link ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/models/mongo_document.rb', line 89 def doc_link if(@doc['_koda_doc_links']) @doc['_koda_doc_links'].to_s else '' end end |
#hidden ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/models/mongo_document.rb', line 81 def hidden if(@doc['_koda_hidden_file']) true else false end end |
#id ⇒ Object
25 26 27 |
# File 'lib/models/mongo_document.rb', line 25 def id @doc['_id'] end |
#id=(value) ⇒ Object
29 30 31 |
# File 'lib/models/mongo_document.rb', line 29 def id=(value) @doc['_id'] = value end |
#last_modified ⇒ Object
19 20 21 22 23 |
# File 'lib/models/mongo_document.rb', line 19 def last_modified if !(@doc['_koda_last_modified']==nil) Time.httpdate(@doc['_koda_last_modified']) end end |
#raw_document ⇒ Object
33 34 35 |
# File 'lib/models/mongo_document.rb', line 33 def raw_document @doc end |
#ref ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/models/mongo_document.rb', line 112 def ref if (@doc['alias'] == nil) @doc['_id'].to_s else @doc['alias'].to_s end end |
#ref=(value) ⇒ Object
108 109 110 |
# File 'lib/models/mongo_document.rb', line 108 def ref=(value) @doc['alias'] = value end |
#standardised_document ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/models/mongo_document.rb', line 45 def standardised_document copy = @doc.clone copy['alias'] = ref copy.delete('_id') if(copy[:_id]) copy.delete(:_id) end copy.delete('_koda_last_modified') copy end |
#stripped_document ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/models/mongo_document.rb', line 97 def stripped_document copy = @doc.clone copy.delete('_id') copy.delete('_koda_last_modified') copy.delete '_koda_indexes' copy.delete '_koda_type' copy.delete '_koda_editor' copy.delete '_koda_doc_links' copy.to_obj end |
#title ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/models/mongo_document.rb', line 56 def title if (@doc['name']) @doc['name'] else if(@doc['_koda_title']) @doc['_koda_title'] else ref end end end |
#type ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/models/mongo_document.rb', line 73 def type if(@doc['_koda_type']) @doc['_koda_type'].to_s else 'anon' end end |
#url ⇒ Object
120 121 122 |
# File 'lib/models/mongo_document.rb', line 120 def url '/api/' + @collection + '/' + ref end |