Module: LexxyRealtime::Collaborative::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/lexxy_realtime/collaborative.rb
Overview
The instance API, present only on models that declared an attribute.
Instance Method Summary collapse
-
#collaborative_document(name) ⇒ Object
The document, if collaboration has started (nil until the first join).
- #collaborative_rich_text?(name) ⇒ Boolean
-
#find_or_create_collaborative_document(name) ⇒ Object
Creates the document on first use.
-
#refresh_collaborative_rich_text(name) ⇒ Object
Reloads and renders the document while holding the record lock, then saves the HTML through the attribute writer.
Instance Method Details
#collaborative_document(name) ⇒ Object
The document, if collaboration has started (nil until the first join).
39 |
# File 'lib/lexxy_realtime/collaborative.rb', line 39 def collaborative_document(name) = public_send("collaborative_document_#{name}") |
#collaborative_rich_text?(name) ⇒ Boolean
36 |
# File 'lib/lexxy_realtime/collaborative.rb', line 36 def collaborative_rich_text?(name) = collaborative_rich_text_names.include?(name.to_sym) |
#find_or_create_collaborative_document(name) ⇒ Object
Creates the document on first use. The association supplies the class, so an encrypted attribute gets a Y::EncryptedDocument.
43 44 45 46 47 48 |
# File 'lib/lexxy_realtime/collaborative.rb', line 43 def find_or_create_collaborative_document(name) collaborative_document(name) || begin association(:"collaborative_document_#{name}").klass.for(self, name) public_send("reload_collaborative_document_#{name}") end end |
#refresh_collaborative_rich_text(name) ⇒ Object
Reloads and renders the document while holding the record lock, then saves the HTML through the attribute writer. Returns false when the document has no state.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/lexxy_realtime/collaborative.rb', line 53 def refresh_collaborative_rich_text(name) ensure_collaborative!(name) document = collaborative_document(name) return false unless document with_lock do strict_loading!(false) if strict_loading? # the writer lazily loads the rich-text row state = document.reload.load_state break false if state.nil? doc = Y::Doc.new doc.apply_update(state) html = Y::Lexxy.new(doc).to_html break false if html.nil? public_send("#{name}=", html) save!(validate: false) # collaboration updates should not run unrelated model validations true end end |