Sha256: 07a361bfd25d3bcc4c98a7425bd52a855e035216e50b72452179db0cee094b9e

Contents?: true

Size: 1.03 KB

Versions: 52

Compression:

Stored size: 1.03 KB

Contents

# Allows constraining routing to components that explicitly declares to use a
# given controller to manage their resources.
#
# It's mainly used to allow users to override the default controller for the
# resources of a given Crud or Form components without having to
# subclass the component and declare all the routes again
#
module Para
  module Routing
    class ComponentControllerConstraint
      attr_reader :controller

      def initialize(controller)
        @controller = controller.to_sym
      end

      def matches?(request)
        component = component_for(request.params[:component_id])
        return false unless component && component.controller
        component.controller.to_sym == controller
      end

      private

      def component_for(component_slug)
        self.class.components[component_slug] ||= Para::Component::Base.find_by_slug(component_slug)
      end

      # Request based components cache
      #
      def self.components
        RequestStore.store['para.components_by_id'] ||= {}
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
para-0.12.4 lib/para/routing/component_controller_constraint.rb
para-0.12.3 lib/para/routing/component_controller_constraint.rb
para-0.12.2 lib/para/routing/component_controller_constraint.rb
para-0.12.1 lib/para/routing/component_controller_constraint.rb
para-0.12.0 lib/para/routing/component_controller_constraint.rb
para-0.11.4 lib/para/routing/component_controller_constraint.rb
para-0.11.3 lib/para/routing/component_controller_constraint.rb
para-0.11.2 lib/para/routing/component_controller_constraint.rb
para-0.11.1 lib/para/routing/component_controller_constraint.rb
para-0.11.0 lib/para/routing/component_controller_constraint.rb
para-0.10.0 lib/para/routing/component_controller_constraint.rb
para-0.9.4 lib/para/routing/component_controller_constraint.rb
para-0.9.3.3 lib/para/routing/component_controller_constraint.rb
para-0.9.3.2 lib/para/routing/component_controller_constraint.rb
para-0.9.3.1 lib/para/routing/component_controller_constraint.rb
para-0.9.2 lib/para/routing/component_controller_constraint.rb
para-0.9.0 lib/para/routing/component_controller_constraint.rb
para-0.8.15 lib/para/routing/component_controller_constraint.rb
para-0.8.14 lib/para/routing/component_controller_constraint.rb
para-0.8.13 lib/para/routing/component_controller_constraint.rb