Sha256: e687235930914f78f31ad632cd6f090970a8e20c303e4ee9c7dbff64c384f109

Contents?: true

Size: 707 Bytes

Versions: 1

Compression:

Stored size: 707 Bytes

Contents

class SiteHub
  class PathDirective
    attr_reader :matcher, :path_template

    def initialize(matcher, path_template)
      @matcher = matcher
      @path_template = path_template
    end

    def match?(url)
      !matcher.match(url).nil?
    end

    def path_template
      @path_template.dup
    end

    def apply(url)
      url_components = matcher.match(url).captures

      path_template.tap do |p|
        url_components.each_with_index do |m, index|
          p.gsub!(RequestMapping::CAPTURE_GROUP_REFERENCE % (index + 1), m)
        end
      end
    end

    def ==(other)
      other.is_a?(PathDirective) && matcher == other.matcher && path_template == other.path_template
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sitehub-0.4.3 lib/sitehub/path_directive.rb