Class: JsDuck::ExtPatterns

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/ext_patterns.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(namespaces) ⇒ ExtPatterns

Returns a new instance of ExtPatterns.



22
23
24
25
26
27
28
29
# File 'lib/jsduck/ext_patterns.rb', line 22

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

Instance Method Details

#matches?(pattern, string) ⇒ Boolean

True when string matches the given pattern type.

Pattern type is one of: “Ext.define”, “Ext.extend”, “Ext.override”, “Ext.emptyFn”

Returns:

  • (Boolean)


35
36
37
# File 'lib/jsduck/ext_patterns.rb', line 35

def matches?(pattern, string)
  @patterns[pattern].include?(string)
end