Class: JsDuck::Js::ExtPatterns
- Inherits:
-
Object
- Object
- JsDuck::Js::ExtPatterns
- 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
-
#configure(opts) ⇒ Object
Reconfigures ExtPatterns with different set of namespaces from command line options.
-
#initialize ⇒ ExtPatterns
constructor
A new instance of ExtPatterns.
-
#matches?(pattern, string) ⇒ Boolean
True when string matches the given pattern type.
-
#set(namespaces) ⇒ Object
Reconfigures patterns with given set of namespaces.
Methods included from Util::Singleton
Constructor Details
#initialize ⇒ ExtPatterns
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
#configure(opts) ⇒ Object
Reconfigures ExtPatterns with different set of namespaces from command line options.
41 42 43 |
# File 'lib/jsduck/js/ext_patterns.rb', line 41 def configure(opts) set(opts.ext_namespaces) if opts.ext_namespaces end |
#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”
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 patterns with given set of namespaces.
46 47 48 49 50 51 52 53 |
# File 'lib/jsduck/js/ext_patterns.rb', line 46 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 |