module LooseLeaf::Document::ClassMethods

Public Instance Methods

collaborative_attributes(*attributes) click to toggle source
# File lib/loose_leaf/document.rb, line 13
def collaborative_attributes(*attributes)
  return @collaborative_attributes if attributes.size.zero?

  @collaborative_attributes = attributes.map(&:to_s)

  bind_collaborative_document_attributes
end
collaborative_key(attribute = nil) click to toggle source
# File lib/loose_leaf/document.rb, line 21
def collaborative_key(attribute = nil)
  return @collaborative_key || :id if attribute.blank?
  @collaborative_key ||= attribute
end
find_by_collaborative_key(key) click to toggle source
# File lib/loose_leaf/document.rb, line 26
def find_by_collaborative_key(key)
  query = {}
  query[collaborative_key] = key
  find_by(query)
end

Private Instance Methods

bind_collaborative_document_attribute(attribute) click to toggle source
Calls superclass method
# File lib/loose_leaf/document.rb, line 40
def bind_collaborative_document_attribute(attribute)
  define_method("collaborative_#{attribute}") do
    collaborative_attribute(attribute).value
  end

  define_method("collaborative_#{attribute}=") do |value|
    collaborative_attribute(attribute).value = value
  end

  # Override the normal setter so that we can update our cache
  define_method("#{attribute}=") do |value|
    super(value)

    collaborative_attribute(attribute).value = value
  end
end
bind_collaborative_document_attributes() click to toggle source
# File lib/loose_leaf/document.rb, line 34
def bind_collaborative_document_attributes
  collaborative_attributes.each do |attribute|
    bind_collaborative_document_attribute(attribute)
  end
end