Class: Cambium::PageTemplate

Inherits:
Object
  • Object
show all
Defined in:
app/models/cambium/page_template.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ PageTemplate

Returns a new instance of PageTemplate.



4
5
6
7
# File 'app/models/cambium/page_template.rb', line 4

def initialize(attrs)
  attributes(attrs)
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



20
21
22
23
24
# File 'app/models/cambium/page_template.rb', line 20

def method_missing(method, *arguments, &block)
  return attributes[method.to_s] if respond_to?(method.to_s)
  return {} if method.to_s == 'fields'
  super
end

Class Method Details

.allObject



30
31
32
# File 'app/models/cambium/page_template.rb', line 30

def self.all
  (app_templates + cambium_templates).flatten.sort_by(&:name)
end

.find(name) ⇒ Object



38
39
40
# File 'app/models/cambium/page_template.rb', line 38

def self.find(name)
  all.select { |t| t.name == name }.first
end

.namesObject



34
35
36
# File 'app/models/cambium/page_template.rb', line 34

def self.names
  all.collect(&:name).flatten.uniq.sort
end

Instance Method Details

#attributes(attrs = nil) ⇒ Object



9
10
11
12
13
14
# File 'app/models/cambium/page_template.rb', line 9

def attributes(attrs = nil)
  @attributes ||= begin
    name = attrs['file_path'].split('/').last.split('.').first
    attrs.merge('name' => name).stringify_keys
  end
end

#has_fields?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/cambium/page_template.rb', line 16

def has_fields?
  respond_to?('fields')
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/cambium/page_template.rb', line 26

def respond_to?(method, include_private = false)
  attributes.keys.include?(method.to_s)
end