Class: SimpleContentManagement::SimplePage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/simple_content_management/simple_page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered_content_pagesObject



43
44
45
# File 'app/models/simple_content_management/simple_page.rb', line 43

def registered_content_pages
  @registered_content_pages ||= YAML.load_file File.join Rails.root, "config", "content_pages.yml"
end

Instance Method Details

#destroyObject



38
39
40
# File 'app/models/simple_content_management/simple_page.rb', line 38

def destroy
  update_attribute :deleted, true
end

#path_namesObject



34
35
36
# File 'app/models/simple_content_management/simple_page.rb', line 34

def path_names
  simple_routes.pluck("path")
end

#simple_routes_listObject



8
9
10
# File 'app/models/simple_content_management/simple_page.rb', line 8

def simple_routes_list
  path_names.join ","
end

#simple_routes_list=(routes_list) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/simple_content_management/simple_page.rb', line 12

def simple_routes_list=(routes_list)
  path_names = routes_list.split ","

  # destroy routes that are no longer required
  self.simple_routes.each do |simple_route|
    simple_route.destroy unless path_names.include? simple_route.path
  end

  # ensure any existing routes are set active to the current page.
  SimpleContentManagement::SimpleRoute.where(path: path_names).each do |simple_route|
    simple_route.simple_page = self
    simple_route.deleted = false
    simple_route.save
    path_names.delete simple_route.path
  end

  # create the remaining routes
  path_names.each do |path_name|
    self.simple_routes.build path: path_name
  end
end