Sha256: 67dc4f067749194923456c9e668fb6b4e71a5ddeaf3a5a9fe857ea97d6797653

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

module Locomotive
  module Steam

    class PageFinderService < Struct.new(:repository)

      include Locomotive::Steam::Services::Concerns::Decorator

      def find(path)
        decorate do
          repository.by_fullpath(path)
        end
      end

      def match(path)
        decorate do
          repository.matching_fullpath(path_combinations(path))
        end
      end

      private

      def path_combinations(path)
        _path_combinations(path.split('/'))
      end

      def _path_combinations(segments, can_include_template = true)
        return nil if segments.empty?
        segment = segments.shift

        (can_include_template ? [segment, WILDCARD] : [segment]).map do |_segment|
          if (_combinations = _path_combinations(segments.clone, can_include_template && _segment != WILDCARD))
            [*_combinations].map do |_combination|
              File.join(_segment, _combination)
            end
          else
            [_segment]
          end
        end.flatten
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/services/page_finder_service.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/services/page_finder_service.rb
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/services/page_finder_service.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/services/page_finder_service.rb
locomotivecms_steam-1.0.0.pre.alpha.1 lib/locomotive/steam/services/page_finder_service.rb
locomotivecms_steam-1.0.0.pre.alpha lib/locomotive/steam/services/page_finder_service.rb