Class: Semistatic::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/semistatic/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.factory(template_name, options) ⇒ Object

Factory a page from the config

Creates the attributes required by the config

Parameters:

  • String

    template_name

  • Hash

    options # the page configuration

Returns:

  • Page



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/semistatic/page.rb', line 27

def self.factory(template_name, options)
  page = new(template_name: template_name)

  options = HashWithIndifferentAccess.new(options)
  options[:parts].each do |name, attributes|
    part = page.parts.build({ name: name })
    part.options = attributes
  end

  page.save(validate: false)
  page
end

Instance Method Details

#part(name) ⇒ Object

get part by its name param

Returns:

  • Part



18
19
20
# File 'app/models/semistatic/page.rb', line 18

def part(name)
  parts.select {|p| p.name.downcase == name.to_s.downcase }.first
end