Class: MenuLink

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

Direct Known Subclasses

CategoryLink, ExternalLink, PageLink

Instance Method Summary collapse

Instance Method Details

#cloneObject



22
23
24
25
26
# File 'app/models/menu_link.rb', line 22

def clone
  menu_link = super
  menu_link.children = self.children.collect(&:clone)
  return menu_link
end

#kindObject



14
15
16
# File 'app/models/menu_link.rb', line 14

def kind
  read_attribute(:type)
end

#kind=(kind) ⇒ Object



18
19
20
# File 'app/models/menu_link.rb', line 18

def kind=(kind)
  write_attribute(:type, kind)
end

#url_and_children_urlsObject



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

def url_and_children_urls
  (self.children.map(&:url) + [self.url])
end

#url_and_parent_urlsObject



42
43
44
45
# File 'app/models/menu_link.rb', line 42

def url_and_parent_urls
  return [self.url] unless self.parent
  (self.parent.url_and_parent_urls + [self.url])
end

#url_match?(url_pattern = '') ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
# File 'app/models/menu_link.rb', line 47

def url_match?(url_pattern='')
  case url_pattern
  when String
    url_and_children_urls.include?("/#{CGI::unescape(url_pattern)}".gsub(/\/+/, '/'))
  when Array
    url_and_children_urls.include?("/#{url_pattern.last}")
  else
    false
  end
end

#url_with_targetObject



28
29
30
31
32
33
34
35
# File 'app/models/menu_link.rb', line 28

def url_with_target
  url_attribute = url_without_target
  if url_attribute.nil? || url_attribute.blank?
    target_id ? target : '#'
  else
    url_attribute
  end
end