Class: JsDuck::Js::ExtPatterns

Inherits:
Object
  • Object
show all
Includes:
Util::Singleton
Defined in:
lib/jsduck/js/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:

ExtPatterns.set(["Ext", "MyApp"])
ExtPatterns.matches?("Ext.define", "MyApp.define") --> true

Instance Method Summary collapse

Methods included from Util::Singleton

included

Constructor Details

#initializeExtPatterns

Returns a new instance of ExtPatterns.



27
28
29
# File 'lib/jsduck/js/ext_patterns.rb', line 27

def initialize
  set(["Ext"])
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/js/ext_patterns.rb', line 35

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

#set(namespaces) ⇒ Object

Reconfigures ExtPatterns with different set of namespaces. Called when –ext-namespaces option is passed to JSDuck.



41
42
43
44
45
46
47
48
# File 'lib/jsduck/js/ext_patterns.rb', line 41

def set(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