class Seiten::PageCollection

Attributes

navigation_id[RW]
pages[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/seiten/page_collection.rb, line 5
def initialize(options = {})
  @navigation_id = options[:navigation_id]
  @pages         = options[:pages] || []
end

Public Instance Methods

all() click to toggle source
# File lib/seiten/page_collection.rb, line 18
def all
  pages.to_a
end
build(options = {}) click to toggle source
# File lib/seiten/page_collection.rb, line 14
def build(options = {})
  Seiten::PageCollectionBuilder.call(self, options)
end
find(id) click to toggle source
# File lib/seiten/page_collection.rb, line 22
def find(id)
  find_by(id: id)
end
find_by(params) click to toggle source
# File lib/seiten/page_collection.rb, line 26
def find_by(params)
  @find_by ||= {}
  return @find_by[params] if @find_by.key?(params)

  @find_by[params] = pages.find do |page|
    params.all? do |k, v|
      page.send(k) == v
    end
  end
end
navigation() click to toggle source
new(params = {}) click to toggle source
# File lib/seiten/page_collection.rb, line 48
def new(params = {})
  page = Seiten::Page.new(params.merge(navigation_id: navigation_id))
  pages << page
  page
end
where(params) click to toggle source
# File lib/seiten/page_collection.rb, line 37
def where(params)
  @where ||= {}
  return @where[params] if @where.key?(params)

  @where[params] = pages.select do |page|
    params.all? do |k, v|
      page.send(k) == v
    end
  end
end