Class: Cmsimple::Path

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

Defined Under Namespace

Classes: Redirect

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_request(request) ⇒ Object



14
15
16
17
18
19
20
# File 'app/models/cmsimple/path.rb', line 14

def self.from_request(request)
  if !request.params.has_key?(:path)
    with_pages.merge(Cmsimple::Page.root).first
  elsif result = find_from_request(request)
    result
  end
end

.from_request!(request) ⇒ Object



22
23
24
# File 'app/models/cmsimple/path.rb', line 22

def self.from_request!(request)
  from_request(request) || raise(ActiveRecord::RecordNotFound.new)
end

.with_pagesObject



26
27
28
# File 'app/models/cmsimple/path.rb', line 26

def self.with_pages
  includes(:page)
end

Instance Method Details

#destinationObject



30
31
32
33
34
35
36
# File 'app/models/cmsimple/path.rb', line 30

def destination
  @destination ||= if redirect?
                     Redirect.new(self)
                   else
                     self.page
                   end
end

#redirect?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/cmsimple/path.rb', line 38

def redirect?
  self.page.blank? || !(self.page.is_root || self.page.uri == self.uri)
end