Sha256: 717edf7fde7977e208fbcb03df0be09bf46c2fedfb550fd9ee69c6d54f79e18d

Contents?: true

Size: 1.11 KB

Versions: 19

Compression:

Stored size: 1.11 KB

Contents

require 'rails'
require 'awesome_nested_set'

module Cable
  module Menu
    module ActsAsCableMenu
      def self.included( base )
        base.send :extend, ClassMethods
      end
  
      module ClassMethods
  
        def acts_as_cable_menu( reflection_options = {} )
          send :include, InstanceMethods
          belongs_to :cable_menuable, reflection_options.merge( :polymorphic => true )
          accepts_nested_attributes_for :cable_menuable
          acts_as_nested_set 
          # :scope => :tree_id
          
          yields self if block_given?
          
        end
      end
  
      module InstanceMethods
    
        def resource
          self.cable_menuable
        end
        
        def resource=( args )
          resource_type, resource_id = args.scan(/(\w+)|\,\s(\d+)\]/).flatten.compact
          if Cable.resources.include?(resource_type)
            self.cable_menuable_id = resource_id
            self.cable_menuable_type = resource_type
          end
        end
    
        def route
          (self.ancestors.collect{|an| an.url } << self.url).join
        end
    
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cable-0.9.17 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.16 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.15 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.14 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.13 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.12 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.11 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.10 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.9 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.8 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.6 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.5 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.4 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.3 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.1 lib/cable/menu/acts_as_cable_menu.rb
cable-0.9.0 lib/cable/menu/acts_as_cable_menu.rb
cable-0.8.6 lib/cable/menu/acts_as_cable_menu.rb
cable-0.8.5 lib/cable/menu/acts_as_cable_menu.rb
cable-0.8.4 lib/cable/menu/acts_as_cable_menu.rb