Sha256: ac7e77f75849ff5ca15ea5df34ca6157fa0db9c044498dd499d5b546e99fa519

Contents?: true

Size: 1.7 KB

Versions: 99

Compression:

Stored size: 1.7 KB

Contents

module ActionView #:nodoc:
  # = Action View PathSet
  #
  # This class is used to store and access paths in Action View. A number of
  # operations are defined so that you can search among the paths in this
  # set and also perform operations on other +PathSet+ objects.
  #
  # A +LookupContext+ will use a +PathSet+ to store the paths in its context.
  class PathSet #:nodoc:
    include Enumerable

    attr_reader :paths

    delegate :[], :include?, :pop, :size, :each, to: :paths

    def initialize(paths = [])
      @paths = typecast paths
    end

    def initialize_copy(other)
      @paths = other.paths.dup
      self
    end

    def to_ary
      paths.dup
    end

    def compact
      PathSet.new paths.compact
    end

    def +(array)
      PathSet.new(paths + array)
    end

    %w(<< concat push insert unshift).each do |method|
      class_eval <<-METHOD, __FILE__, __LINE__ + 1
        def #{method}(*args)
          paths.#{method}(*typecast(args))
        end
      METHOD
    end

    def find(*args)
      find_all(*args).first || raise(MissingTemplate.new(self, *args))
    end

    def find_all(path, prefixes = [], *args)
      prefixes = [prefixes] if String === prefixes
      prefixes.each do |prefix|
        paths.each do |resolver|
          templates = resolver.find_all(path, prefix, *args)
          return templates unless templates.empty?
        end
      end
      []
    end

    def exists?(path, prefixes, *args)
      find_all(path, prefixes, *args).any?
    end

    private

    def typecast(paths)
      paths.map do |path|
        case path
        when Pathname, String
          OptimizedFileSystemResolver.new path.to_s
        else
          path
        end
      end
    end
  end
end

Version data entries

99 entries across 95 versions & 9 rubygems

Version Path
activejob-lock-0.0.2 rails/actionview/lib/action_view/path_set.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/actionview-4.1.13/lib/action_view/path_set.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/actionview-4.2.4/lib/action_view/path_set.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/actionview-4.1.13/lib/action_view/path_set.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/actionview-4.2.4/lib/action_view/path_set.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/actionview-4.2.4/lib/action_view/path_set.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/actionview-4.1.13/lib/action_view/path_set.rb
actionview-4.1.14 lib/action_view/path_set.rb
actionview-4.2.5 lib/action_view/path_set.rb
actionview-4.2.5.rc2 lib/action_view/path_set.rb
actionview-4.1.14.rc2 lib/action_view/path_set.rb
actionview-4.2.5.rc1 lib/action_view/path_set.rb
actionview-4.1.14.rc1 lib/action_view/path_set.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.4/lib/action_view/path_set.rb
actionview-4.2.4 lib/action_view/path_set.rb
actionview-4.1.13 lib/action_view/path_set.rb
actionview-4.2.4.rc1 lib/action_view/path_set.rb
actionview-4.1.13.rc1 lib/action_view/path_set.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/actionview-4.2.3/lib/action_view/path_set.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/actionview-4.2.3/lib/action_view/path_set.rb