Module: LooseLeaf::Document

Extended by:
ActiveSupport::Concern
Defined in:
lib/loose_leaf/document.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#apply_operation(data) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/loose_leaf/document.rb', line 66

def apply_operation(data)
  operation = OT::TextOperation.from_a data[:operation]
  attribute = data[:attribute]
  version = data[:version]

  collaborative_attribute(attribute).apply_operation(operation, version)
end

#clear_collaborative_cache(attribute) ⇒ Object



87
88
89
# File 'lib/loose_leaf/document.rb', line 87

def clear_collaborative_cache(attribute)
  collaborative_attribute(attribute).clear_cache
end

#collaborative_attribute(attribute_name) ⇒ Object



58
59
60
# File 'lib/loose_leaf/document.rb', line 58

def collaborative_attribute(attribute_name)
  @collaborative_attributes[attribute_name.to_s]
end

#collaborative_idObject



62
63
64
# File 'lib/loose_leaf/document.rb', line 62

def collaborative_id
  @collaborative_id ||= send(self.class.collaborative_key)
end

#commit_collaborative_attributes(*attributes) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/loose_leaf/document.rb', line 74

def commit_collaborative_attributes(*attributes)
  attributes = attributes.flatten.map(&:to_s)

  # Intersect with allowed attributes
  attributes &= self.class.collaborative_attributes

  attributes.each do |attribute|
    send("#{attribute}=", send("collaborative_#{attribute}"))
  end

  save
end

#setup_collaborative_attributesObject



91
92
93
94
95
96
97
# File 'lib/loose_leaf/document.rb', line 91

def setup_collaborative_attributes
  @collaborative_attributes = {}

  self.class.collaborative_attributes.each do |attribute|
    @collaborative_attributes[attribute] = DocumentAttribute.new(self, attribute)
  end
end