Class: Rooftop::Menus::Item

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/rooftop/menus/item.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Item



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rooftop/menus/item.rb', line 4

def initialize(args)
  args[:object_type] = args[:object]
  super
  # If this menu item has children, create a MenuItem for each one
  if self.children
    self.children = children.collect do |child|
      Item.new(child)
    end
  end

end

Instance Method Details

#objectObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/rooftop/menus/item.rb', line 16

def object
  if self.type == "post_type"
    begin
      klass = Rooftop.configuration.post_type_mapping[self.object_type] || self.object_type.classify.constantize
      klass.find_by(slug: self.slug).first
    rescue
      raise UnmappedObjectError, "Couldn't find an mapping between the #{self.object_type} post type and a class in your code."
    end
  end
end