Sha256: ee4b443709e2829081b89a19702b2acc4ac489089563b1944a37fe823580b4fb

Contents?: true

Size: 978 Bytes

Versions: 67

Compression:

Stored size: 978 Bytes

Contents

module Jpmobile
  class PathSet < Array
    %w(initialize << concat insert push unshift).each do |method|
      class_eval <<-METHOD, __FILE__, __LINE__ + 1
        def #{method}(*args)
          super
          typecast!
        end
      METHOD
    end

    def find(path, prefix = nil, partial = false, details = {}, key = nil)
      template = find_all(path, prefix, partial, details, key).first
      raise MissingTemplate.new(self, "#{prefix}/#{path}", details, partial) unless template
      template
    end

    def find_all(*args)
      each do |resolver|
        templates = resolver.find_all(*args)
        return templates unless templates.empty?
      end
      []
    end

    def exists?(*args)
      find_all(*args).any?
    end

    protected

    def typecast!
      each_with_index do |path, i|
        path = path.to_s if path.is_a?(Pathname)
        next unless path.is_a?(String)
        self[i] = Jpmobile::Resolver.new(path)
      end
    end
  end
end

Version data entries

67 entries across 62 versions & 1 rubygems

Version Path
jpmobile-4.2.5 lib/jpmobile/path_set.rb
jpmobile-4.2.4 lib/jpmobile/path_set.rb
jpmobile-5.0.0 lib/jpmobile/path_set.rb
jpmobile-5.0.0.beta3 lib/jpmobile/path_set.rb
jpmobile-4.1.5 lib/jpmobile/path_set.rb
jpmobile-5.0.0.beta2 lib/jpmobile/path_set.rb
jpmobile-4.2.3 lib/jpmobile/path_set.rb
jpmobile-4.2.2 lib/jpmobile/path_set.rb
jpmobile-4.2.1 lib/jpmobile/path_set.rb
jpmobile-5.0.0.beta1 lib/jpmobile/path_set.rb
jpmobile-4.2.0 lib/jpmobile/path_set.rb
jpmobile-3.0.9 lib/jpmobile/path_set.rb
jpmobile-4.1.4 lib/jpmobile/path_set.rb
jpmobile-4.0.1 lib/jpmobile/path_set.rb
jpmobile-4.1.1 lib/jpmobile/path_set.rb
jpmobile-4.1.0 lib/jpmobile/path_set.rb
jpmobile-3.0.8 lib/jpmobile/path_set.rb
jpmobile-4.1.0.rc1 lib/jpmobile/path_set.rb
jpmobile-4.0.0 lib/jpmobile/path_set.rb
jpmobile-3.0.7 lib/jpmobile/path_set.rb