Module: Pageflow::RevisionComponent::ClassMethods

Defined in:
lib/pageflow/revision_component.rb

Instance Method Summary collapse

Instance Method Details

#all_for_revision(revision) ⇒ Object



40
41
42
# File 'lib/pageflow/revision_component.rb', line 40

def all_for_revision(revision)
  where(revision_id: revision.id)
end

#create_with_lock!(attributes, &block) ⇒ Object

Recommended way to create revision components. Uses an advisory lock to ensure concurrently created records are not assigned the same perma id.



34
35
36
37
38
# File 'lib/pageflow/revision_component.rb', line 34

def create_with_lock!(attributes, &block)
  with_advisory_lock_for_perma_id_generation! do
    create!(attributes, &block)
  end
end

#from_perma_ids(revision, perma_ids) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/pageflow/revision_component.rb', line 44

def from_perma_ids(revision, perma_ids)
  return [] if revision.blank? || perma_ids.blank?

  perma_ids.map do |perma_id|
    find_by_revision_id_and_perma_id(revision.id, perma_id)
  end.compact
end