Sha256: d3de4ddd75180629fd790f2c0b4050a608e6fb1ed2c042d2c857710e4464fcf8

Contents?: true

Size: 1.73 KB

Versions: 14

Compression:

Stored size: 1.73 KB

Contents

module JsDuck

  # Identifies Ext JS builtins like Ext.define and Ext.extend, taking
  # also into account the possibility of aliasing the Ext namespace.
  #
  # For example when the following command line option is used:
  #
  #     --ext-namespaces=Ext,MyApp
  #
  # we need to identify both Ext.define and MyApp.define, but
  # Ext.define is additionally aliased withing ExtJS as
  # Ext.ClassManager.create, so we also need to recognize
  # Ext.ClassManager.create and MyApp.ClassManager.create.
  #
  # The matches? method will take care of identifying all these four
  # cases:
  #
  #     ps = ExtPatterns.new(["Ext", "MyApp"])
  #     matches?("Ext.define", "MyApp.define") --> true
  #
  class ExtPatterns
    def initialize(namespaces)
      @patterns = {
        "Ext.define" => build_patterns(namespaces, [".define", ".ClassManager.create"]),
        "Ext.extend" => build_patterns(namespaces, [".extend"]),
        "Ext.override" => build_patterns(namespaces, [".override"]),
        "Ext.emptyFn" => build_patterns(namespaces, [".emptyFn"]),
      }
    end

    # True when string matches the given pattern type.
    #
    # Pattern type is one of: "Ext.define", "Ext.extend",
    # "Ext.override", "Ext.emptyFn"
    def matches?(pattern, string)
      @patterns[pattern].include?(string)
    end

    private

    # Given Array of alternate Ext namespaces builds list of patterns
    # for detecting Ext.define or some other construct:
    #
    # build_patterns(["Ext", "Foo"], [".define"]) --> ["Ext.define", "Foo.define"]
    #
    def build_patterns(namespaces, suffixes)
      patterns = []
      namespaces.each do |ns|
        suffixes.each do |suffix|
          patterns << ns + suffix
        end
      end
      patterns
    end

  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
jsduck-4.10.4 lib/jsduck/ext_patterns.rb
jsduck-4.10.3 lib/jsduck/ext_patterns.rb
jsduck-4.10.2 lib/jsduck/ext_patterns.rb
jsduck-4.10.1 lib/jsduck/ext_patterns.rb
jsduck-4.10.0 lib/jsduck/ext_patterns.rb
jsduck-4.9.0 lib/jsduck/ext_patterns.rb
jsduck-4.8.0 lib/jsduck/ext_patterns.rb
jsduck-4.7.1 lib/jsduck/ext_patterns.rb
jsduck-4.7.0 lib/jsduck/ext_patterns.rb
jsduck-4.6.2 lib/jsduck/ext_patterns.rb
jsduck-4.6.1 lib/jsduck/ext_patterns.rb
jsduck-4.6.0 lib/jsduck/ext_patterns.rb
jsduck-4.5.1 lib/jsduck/ext_patterns.rb
jsduck-4.5.0 lib/jsduck/ext_patterns.rb