Class: PageRoute

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

Instance Method Summary collapse

Instance Method Details

#add_condition(name, value) ⇒ Object



15
16
17
# File 'app/models/page_route.rb', line 15

def add_condition(name, value)
  conditions.build(:name => name.to_s, :value => value.to_s)
end

#add_requirement(name, value) ⇒ Object



19
20
21
# File 'app/models/page_route.rb', line 19

def add_requirement(name, value)
  requirements.build(:name => name.to_s, :value => value.to_s)
end

#conditions_mapObject



23
24
25
# File 'app/models/page_route.rb', line 23

def conditions_map
  conditions.inject({}){|acc, e| acc[e.name.to_sym] = e.value.to_sym; acc}
end

#execute(controller) ⇒ Object

This is called by an instance of the content controller in the process of rendering a page. This will eval the code stored in this page route in the context of the controller.

The main purpose of this method is to set instance variables that will be used by one or more portlets when the page is rendered.

To set an instance variable, the code should contain something like:

@news_article = NewsArticle.find(params[:id]))


54
55
56
# File 'app/models/page_route.rb', line 54

def execute(controller)
  controller.instance_eval(code) unless code.blank?
end

#options_mapObject

This is used in defining the route in the ActionController::Routing



36
37
38
39
40
41
42
43
44
45
# File 'app/models/page_route.rb', line 36

def options_map
  m = {:controller => "cms/content", :action => "show_page_route"}
  
  m[:_page_route_id] = self.id.to_s
  
  m[:requirements] = requirements_map
  m[:conditions] = conditions_map
  
  m
end

#reload_routesObject



11
12
13
# File 'app/models/page_route.rb', line 11

def reload_routes
  ActionController::Routing::Routes.load!
end

#requirements_mapObject



27
28
29
# File 'app/models/page_route.rb', line 27

def requirements_map
  requirements.inject({}){|acc, e| acc[e.name.to_sym] = Regexp.new(e.value); acc}
end

#route_nameObject



31
32
33
# File 'app/models/page_route.rb', line 31

def route_name
  name ? name.to_slug.gsub('-','_') : nil
end