Class: BrickLayer::Route
- Inherits:
-
Object
- Object
- BrickLayer::Route
- Includes:
- Mongoid::Ancestry, Mongoid::Document
- Defined in:
- app/models/brick_layer/route.rb
Class Method Summary collapse
-
.root ⇒ Object
Grab or create root.
Instance Method Summary collapse
-
#change_parent_to(parent_route) ⇒ Object
Change parent.
-
#full_path ⇒ Object
Display the full path for a route.
-
#set_full_path_cache ⇒ Object
Set the full path cache for easy lookup.
-
#set_parent ⇒ Object
Use this method to keep up with hiearchry for #full_path.
-
#to_s ⇒ Object
For parent purposes.
-
#update_routes ⇒ Object
Update Children Routes.
Class Method Details
.root ⇒ Object
Grab or create root
21 22 23 24 25 26 27 28 29 |
# File 'app/models/brick_layer/route.rb', line 21 def self.root root_exist = BrickLayer::Route.where(:slug => "").count > 0 if root_exist return BrickLayer::Route.where(:slug => "").first else return BrickLayer::Route.create(:slug => "") end end |
Instance Method Details
#change_parent_to(parent_route) ⇒ Object
Change parent
58 59 60 |
# File 'app/models/brick_layer/route.rb', line 58 def change_parent_to(parent_route) self.parent_id = parent_route.id end |
#full_path ⇒ Object
Display the full path for a route
32 33 34 |
# File 'app/models/brick_layer/route.rb', line 32 def full_path self.ancestors.sort_by { |x| x.ancestry.to_s }.map { |x| x.slug }.join("/") + "/#{self.slug}" end |
#set_full_path_cache ⇒ Object
Set the full path cache for easy lookup
49 50 51 52 53 54 55 |
# File 'app/models/brick_layer/route.rb', line 49 def set_full_path_cache unless self.slug.blank? self.full_path_cache = self.full_path else self.full_path_cache = "" end end |
#set_parent ⇒ Object
Use this method to keep up with hiearchry for #full_path
42 43 44 45 46 |
# File 'app/models/brick_layer/route.rb', line 42 def set_parent unless parent_id.blank? self.current_parent_id = parent_id.to_s end end |
#to_s ⇒ Object
For parent purposes
37 38 39 |
# File 'app/models/brick_layer/route.rb', line 37 def to_s slug.blank? ? "home (root)" : slug end |
#update_routes ⇒ Object
Update Children Routes
63 64 65 66 67 |
# File 'app/models/brick_layer/route.rb', line 63 def update_routes unless self.children.blank? self.children.each { |r| r.save } end end |