Sha256: 2298ca713c713509102859d958eb49458c911146d8750dd7ea9c5a7aac6a1a86

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

module Apitizer
  module Routing
    module Node
      class Collection < Base
        def initialize(name, only: nil, except: [])
          @name = name
          @actions = (only && Array(only) || Apitizer.actions) - Array(except)
        end

        def recognize?(steps)
          @name == steps.first
        end

        def permit?(action, on:)
          @actions.include?(action) && on == Helper.action_scope(action)
        end

        private

        def walk(steps, path)
          path.advance(steps.shift, node: self, on: :collection)

          return if steps.empty?

          children.each do |child|
            next unless child.respond_to?(:on?) && child.on?(:collection)
            return if child.recognize?(steps)
          end

          path.advance(steps.shift, node: self, on: :member)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apitizer-0.0.2 lib/apitizer/routing/node/collection.rb