Sha256: 4e1be010b90a4734147aeaa587bf33f96d40a2e50167f9584d4e4425201263a9

Contents?: true

Size: 593 Bytes

Versions: 2

Compression:

Stored size: 593 Bytes

Contents

require_relative '../collection'
class SiteHub
  class Collection < Hash
    class RouteCollection < Collection

      def add id, route, *opts
        self[id] = route
      end

      def valid?
        !self.empty?
      end

      def resolve(env: nil)
        return self.values.first unless self.values.find { |route| route.rule }
        result = self.values.find { |route| route.applies?(env) }
        result && result.resolve(env: env)
      end

      def transform &block
        each  do |id, value|
          self[id] = block.call(value)
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sitehub-0.4.2 lib/sitehub/collection/route_collection.rb
sitehub-0.4.1 lib/sitehub/collection/route_collection.rb