Sha256: c56b63b5bf82434629cfa84779423f8f10b1bc49a5154c3af97c3861463a33b2

Contents?: true

Size: 1.08 KB

Versions: 18

Compression:

Stored size: 1.08 KB

Contents

class AdminAssistant
  class Route
    attr_reader :admin_assistant
    
    def initialize(admin_assistant)
      @admin_assistant = admin_assistant
    end
    
    def add(binding)
      route_str = "resources(:#{resource})"
      unless autocomplete_actions.empty?
        route_str << " do "
        autocomplete_actions.each do |action|
          route_str << " get :#{action}, :on => :collection;"
        end
        route_str << " end "
      end
      if namespace
        route_str = "namespace(:#{namespace}) do " + route_str + " end"
      end
      eval(route_str, binding)
    end
    
    def autocomplete_actions
      admin_assistant.autocomplete_actions
    end
    
    def controller
      admin_assistant.controller_class
    end
    
    def namespace
      name = controller.name.gsub(/Controller$/, '').underscore
      if name =~ %r|(.*)/(.*)|
        $1.to_sym
      end
    end
    
    def resource
      name = controller.name.gsub(/Controller$/, '').underscore
      if name =~ %r|(.*)/(.*)|
        $2.to_sym
      else
        name.to_sym
      end
    end
  end
end


Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
admin_assistant-2.4.0 lib/admin_assistant/route.rb
admin_assistant-2.3.2 lib/admin_assistant/route.rb
admin_assistant-2.3.1 lib/admin_assistant/route.rb
admin_assistant-2.3.0 lib/admin_assistant/route.rb
admin_assistant-2.2.8 lib/admin_assistant/route.rb
admin_assistant-2.2.7 lib/admin_assistant/route.rb
admin_assistant-2.2.6 lib/admin_assistant/route.rb
admin_assistant-2.2.5 lib/admin_assistant/route.rb
admin_assistant-2.2.4 lib/admin_assistant/route.rb
admin_assistant-2.2.3 lib/admin_assistant/route.rb
admin_assistant-2.2.2 lib/admin_assistant/route.rb
admin_assistant-2.2.1 lib/admin_assistant/route.rb
admin_assistant-2.2.0 lib/admin_assistant/route.rb
admin_assistant-2.1.1 lib/admin_assistant/route.rb
admin_assistant-2.1.0 lib/admin_assistant/route.rb
admin_assistant-2.0.1 lib/admin_assistant/route.rb
admin_assistant-2.0.0 lib/admin_assistant/route.rb
admin_assistant-2.0.0.pre2 lib/admin_assistant/route.rb