Class: Blog::Context

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.context_for_route(route) ⇒ Object

give us either the full_route (i.e. news) or terse_route (n) version and we will give you the blog context.



25
26
27
28
29
30
31
# File 'app/models/blog/context.rb', line 25

def self.context_for_route(route)
  # We do not keep slashes as part of the context routes
  route.gsub!(/^\//,'') if route.present?
  context = context_for_route_type(:terse, route) || context_for_route_type(:full, route)
  raise "No context found for route #{route}. Have you created it yet?" unless context.present?
  context
end

.selectionsObject



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

def self.selections
  Blog::Context.order('full_route desc').collect {|c| [ "/#{c.full_route}", c.id ] }
end

Instance Method Details

#route_match?(type, path) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'app/models/blog/context.rb', line 19

def route_match?(type, path)
  full_route = self.send("#{type.to_s}_route")
  path.match(/^(\/)?#{full_route}(\/)?$/).present?
end