Module: Motor::Notes::Persist

Defined in:
lib/motor/notes/persist.rb

Constant Summary collapse

TAG_REGEXP =
/#\w+?\b/.freeze

Class Method Summary collapse

Class Method Details

.broadcast_note(note) ⇒ Object



24
25
26
27
28
29
# File 'lib/motor/notes/persist.rb', line 24

def broadcast_note(note)
  Motor::NotesChannel.broadcast_to(
    note.values_at(:record_type, :record_id).join(':'),
    ['update', note.as_json(include: %i[author tags reminders])]
  )
end

.call(note, current_user) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/motor/notes/persist.rb', line 10

def call(note, current_user)
  note.author ||= current_user

  tags = parse_tag_names(note)

  Motor::Notes::Tags.assign_tags(note, tags)

  note.save!

  broadcast_note(note)

  note
end

.parse_tag_names(note) ⇒ Object



31
32
33
# File 'lib/motor/notes/persist.rb', line 31

def parse_tag_names(note)
  note.body.scan(TAG_REGEXP).pluck(1..)
end