Module: ActiveMetadata::Persistence::Note::InstanceMethods
- Defined in:
- lib/active_metadata/persistence/note.rb
Instance Method Summary collapse
- #count_notes_for(field) ⇒ Object
- #create_note_for(field, note, starred = nil, group = nil) ⇒ Object
- #create_notes_for(field, notes) ⇒ Object
- #delete_note(id) ⇒ Object
- #find_note_by_id(id) ⇒ Object
- #has_notes_for(field) ⇒ Object
- #notes_for(field, order_by = "updated_at DESC") ⇒ Object
-
#star_note(id) ⇒ Object
star a note reload the cache calling update.
-
#starred_notes ⇒ Object
return all the starred notes for the current model and for any field datas does not come from cache.
-
#starred_notes_for(field) ⇒ Object
return all the starred notes for a particular field datas does not come from cache.
-
#unstar_note(id) ⇒ Object
unstar a note reload the cache calling update.
- #update_note(id, note, starred = nil) ⇒ Object
Instance Method Details
#count_notes_for(field) ⇒ Object
62 63 64 |
# File 'lib/active_metadata/persistence/note.rb', line 62 def count_notes_for field notes_for(field).size end |
#create_note_for(field, note, starred = nil, group = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_metadata/persistence/note.rb', line 9 def create_note_for(field, note, starred=nil, group=nil) ActiveMetadata::Note.create!( :document_id => , :document_class => , :label => field.to_s, :note => note, :created_by => current_user_id, :starred => !!starred, :group => group) reload_notes_cache_for field self.send(:send_notification, field, "", note, :note_message, current_user_id) end |
#create_notes_for(field, notes) ⇒ Object
46 47 48 |
# File 'lib/active_metadata/persistence/note.rb', line 46 def create_notes_for(field, notes) notes.each { |note| create_note_for field, note } end |
#delete_note(id) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/active_metadata/persistence/note.rb', line 50 def delete_note(id) note = ActiveMetadata::Note.find(id) old_value = note.note note.destroy reload_notes_cache_for note.label self.send(:send_notification, note.label, old_value, "", :note_message) end |
#find_note_by_id(id) ⇒ Object
42 43 44 |
# File 'lib/active_metadata/persistence/note.rb', line 42 def find_note_by_id(id) ActiveMetadata::Note.find(id) end |
#has_notes_for(field) ⇒ Object
58 59 60 |
# File 'lib/active_metadata/persistence/note.rb', line 58 def has_notes_for field notes_for(field).size == 0 ? false : true end |
#notes_for(field, order_by = "updated_at DESC") ⇒ Object
36 37 38 39 40 |
# File 'lib/active_metadata/persistence/note.rb', line 36 def notes_for(field, order_by="updated_at DESC") Rails.cache.fetch(notes_cache_key(field), :expires_in => ActiveMetadata::CONFIG['cache_expires_in'].minutes) do fetch_notes_for field, nil, order_by end end |
#star_note(id) ⇒ Object
star a note reload the cache calling update
80 81 82 83 |
# File 'lib/active_metadata/persistence/note.rb', line 80 def star_note(id) n = ActiveMetadata::Note.find(id) update_note id, n.note, true end |
#starred_notes ⇒ Object
return all the starred notes for the current model and for any field datas does not come from cache
68 69 70 |
# File 'lib/active_metadata/persistence/note.rb', line 68 def starred_notes fetch_notes_for nil, true end |
#starred_notes_for(field) ⇒ Object
return all the starred notes for a particular field datas does not come from cache
74 75 76 |
# File 'lib/active_metadata/persistence/note.rb', line 74 def starred_notes_for(field) fetch_notes_for field, true end |
#unstar_note(id) ⇒ Object
unstar a note reload the cache calling update
87 88 89 90 |
# File 'lib/active_metadata/persistence/note.rb', line 87 def unstar_note(id) n = ActiveMetadata::Note.find(id) update_note id, n.note, false end |
#update_note(id, note, starred = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_metadata/persistence/note.rb', line 23 def update_note(id, note, starred=nil) n = ActiveMetadata::Note.find(id) old_value = n.note attributes = {:note => note, :updated_by => current_user_id, :updated_at => Time.now.utc} #mass assign starred inly if provided unless starred.nil? attributes[:starred] = starred end n.update_attributes! attributes reload_notes_cache_for n.label self.send(:send_notification, n.label, old_value, note, :note_message, current_user_id) end |