Class: Seiten::Navigation

Inherits:
Object
  • Object
show all
Defined in:
lib/seiten/navigation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Navigation

Returns a new instance of Navigation.



5
6
7
8
9
10
11
# File 'lib/seiten/navigation.rb', line 5

def initialize(options={})
  @name   = options[:name].to_s
  @locale = options[:locale].to_s
  @config = options[:config] || File.join(Rails.root, Seiten.config[:config_dir], "#{id}.yml")
  @dir    = options[:dir]    || File.join(Rails.root, Seiten.config[:pages_dir], @name, @locale)
  @page_collection = Seiten::PageCollection.new(navigation_id: id)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/seiten/navigation.rb', line 3

def config
  @config
end

#dirObject

Returns the value of attribute dir.



3
4
5
# File 'lib/seiten/navigation.rb', line 3

def dir
  @dir
end

#localeObject

Returns the value of attribute locale.



3
4
5
# File 'lib/seiten/navigation.rb', line 3

def locale
  @locale
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/seiten/navigation.rb', line 3

def name
  @name
end

#page_collectionObject

Returns the value of attribute page_collection.



3
4
5
# File 'lib/seiten/navigation.rb', line 3

def page_collection
  @page_collection
end

Class Method Details

.find_by(params = {}) ⇒ Object



14
15
16
# File 'lib/seiten/navigation.rb', line 14

def find_by(params={})
  where(params).first
end

.where(params = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/seiten/navigation.rb', line 18

def where(params={})
  Seiten.navigations.select do |navigation|
    params.all? do |param|
      navigation.send(param[0]) == param[1]
    end
  end
end

Instance Method Details

#idObject



27
28
29
# File 'lib/seiten/navigation.rb', line 27

def id
  "%s.%s" % [name, locale]
end

#pagesObject



31
32
33
# File 'lib/seiten/navigation.rb', line 31

def pages
  page_collection
end

#pages=(pages_array) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/seiten/navigation.rb', line 35

def pages=(pages_array)
  page_collection.pages = pages_array.map { |page| page.navigation_id = id; page }
  # return page_collection
  # NOTE: This doesn't work and just returns page_array.
  # I think because page_collection#pages= attr_accessor is called first
  # and thus why our return call is ignored.
end