Class: Seiten::PageCollection
- Inherits:
-
Object
- Object
- Seiten::PageCollection
- Defined in:
- lib/seiten/page_collection.rb
Instance Attribute Summary collapse
-
#navigation_id ⇒ Object
Returns the value of attribute navigation_id.
-
#pages ⇒ Object
Returns the value of attribute pages.
Instance Method Summary collapse
- #all ⇒ Object
- #build(options = {}) ⇒ Object
- #find(id) ⇒ Object
- #find_by(params) ⇒ Object
-
#initialize(options = {}) ⇒ PageCollection
constructor
A new instance of PageCollection.
- #navigation ⇒ Object
- #new(params = {}) ⇒ Object
- #where(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ PageCollection
Returns a new instance of PageCollection.
5 6 7 8 |
# File 'lib/seiten/page_collection.rb', line 5 def initialize( = {}) @navigation_id = [:navigation_id] @pages = [:pages] || [] end |
Instance Attribute Details
#navigation_id ⇒ Object
Returns the value of attribute navigation_id.
3 4 5 |
# File 'lib/seiten/page_collection.rb', line 3 def @navigation_id end |
#pages ⇒ Object
Returns the value of attribute pages.
3 4 5 |
# File 'lib/seiten/page_collection.rb', line 3 def pages @pages end |
Instance Method Details
#all ⇒ Object
18 19 20 |
# File 'lib/seiten/page_collection.rb', line 18 def all pages.to_a end |
#build(options = {}) ⇒ Object
14 15 16 |
# File 'lib/seiten/page_collection.rb', line 14 def build( = {}) Seiten::PageCollectionBuilder.call(self, ) end |
#find(id) ⇒ Object
22 23 24 |
# File 'lib/seiten/page_collection.rb', line 22 def find(id) find_by(id: id) end |
#find_by(params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Object
10 11 12 |
# File 'lib/seiten/page_collection.rb', line 10 def Seiten::Navigation.find_by(id: ) end |
#new(params = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/seiten/page_collection.rb', line 48 def new(params = {}) page = Seiten::Page.new(params.merge(navigation_id: )) pages << page page end |
#where(params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# 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 |