Class: Locomotive::Steam::PageRepository

Inherits:
Object
  • Object
show all
Includes:
Models::Repository
Defined in:
lib/locomotive/steam/repositories/page_repository.rb

Instance Attribute Summary

Attributes included from Models::Repository

#adapter, #local_conditions, #scope

Instance Method Summary collapse

Methods included from Models::Repository

#base_url, #build, #count, #create, #delete, #find, #first, #i18n_value_of, #inc, #initialize, #initialize_copy, #k, #last, #mapper, #prepare_conditions, #query, #update

Instance Method Details

#all(conditions = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 18

def all(conditions = {})
  query do
    where(conditions || {}).
      order_by(depth: :asc, position: :asc)
  end.all
end

#ancestors_of(page) ⇒ Object

Note: Ancestors and self



71
72
73
74
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 71

def ancestors_of(page)
  return [] if page.nil?
  all(k(:_id, :in) => page.parent_ids + [page._id])
end

#by_fullpath(path) ⇒ Object



43
44
45
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 43

def by_fullpath(path)
  first { where(fullpath: path) }
end

#by_handle(handle) ⇒ Object



39
40
41
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 39

def by_handle(handle)
  first { where(handle: handle) }
end

#children_of(page) ⇒ Object



76
77
78
79
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 76

def children_of(page)
  return [] if page.nil?
  all(parent_id: page._id)
end

#editable_element_for(page, block, slug) ⇒ Object



86
87
88
89
90
91
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 86

def editable_element_for(page, block, slug)
  return nil if page.nil? || page.editable_elements.nil?
  page.editable_elements.first do
    where(block: block, slug: slug)
  end
end

#editable_elements_of(page) ⇒ Object



81
82
83
84
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 81

def editable_elements_of(page)
  return nil if page.nil?
  page.editable_elements
end

#matching_fullpath(list) ⇒ Object



47
48
49
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 47

def matching_fullpath(list)
  all(k(:fullpath, :in) => list)
end

#only_handle_and_fullpathObject



32
33
34
35
36
37
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 32

def only_handle_and_fullpath
  query do
    where(k(:handle, :ne) => nil).
      only(:_id, :title, :handle, :fullpath)
  end.all.tap { mapper.reset_entity_map }
end

#parent_of(page) ⇒ Object



65
66
67
68
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 65

def parent_of(page)
  return nil if page.nil? || page.index?
  first { where(_id: page.parent_id) }
end

#publishedObject



25
26
27
28
29
30
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 25

def published
  query do
    where(published: true).
      order_by(depth: :asc, position: :asc)
  end.all
end

#rootObject



61
62
63
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 61

def root
  first { where(fullpath: 'index') }
end

#template_for(entry, handle = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 51

def template_for(entry, handle = nil)
  conditions = { templatized: true, target_klass_name: entry.try(:_class_name) }

  conditions[:handle] = handle if handle

  all(conditions).first.tap do |page|
    page.content_entry = entry if page
  end
end