Sha256: ad61d5ba84a2536936c3d7894feed55b1bb15eaa571c5031a9f022e33bd06aa8

Contents?: true

Size: 1.29 KB

Versions: 25

Compression:

Stored size: 1.29 KB

Contents

module Rabl
  # DependencyTracker for ActionView to support cache digest
  class Tracker
    # Matches:
    #   extends "categories/show"
    EXTENDS_DEPENDENCY = /
      extends\s*              # extends, followed by optional whitespace
      \(?                     # start an optional parenthesis for the extends call
      \s*["']([0-9a-z_\/\.]+) # the template name itself
    /x

    # Matches:
    #   partial "categories/show"
    PARTIAL_DEPENDENCY = /
      partial\s*              # partial, followed by optional whitespace
      \(?                     # start an optional parenthesis for the partial call
      \s*["']([0-9a-z_\/\.]+) # the template name itself
    /x

    def self.call(name, template)
      new(name, template).dependencies
    end

    def initialize(name, template)
      @name, @template = name, template
    end

    def dependencies
      (extends_dependencies + partial_dependencies).uniq
    end

    attr_reader :name, :template
    private :name, :template

    private

      def source
        template.source
      end

      def directory
        name.split("/")[0..-2].join("/")
      end

      def extends_dependencies
        source.scan(EXTENDS_DEPENDENCY).flatten
      end

      def partial_dependencies
        source.scan(PARTIAL_DEPENDENCY).flatten
      end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
rabl-0.17.0 lib/rabl/tracker.rb
rabl-0.16.1 lib/rabl/tracker.rb
rabl-0.16.0 lib/rabl/tracker.rb
rabl-0.15.0 lib/rabl/tracker.rb
rabl-0.14.5 lib/rabl/tracker.rb
rabl-0.14.4 lib/rabl/tracker.rb
rabl-0.14.3 lib/rabl/tracker.rb
rabl-0.14.2 lib/rabl/tracker.rb
rabl-0.14.1 lib/rabl/tracker.rb
rabl-0.14.0 lib/rabl/tracker.rb
rabl-0.13.1 lib/rabl/tracker.rb
rabl-0.13.0 lib/rabl/tracker.rb
rabl-0.12.0 lib/rabl/tracker.rb
rabl-0.11.8 lib/rabl/tracker.rb
rabl-0.11.7 lib/rabl/tracker.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rabl-0.11.6/lib/rabl/tracker.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rabl-0.11.6/lib/rabl/tracker.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rabl-0.11.6/lib/rabl/tracker.rb
rabl-0.11.6 lib/rabl/tracker.rb
rabl-0.11.5 lib/rabl/tracker.rb