Class: NetLinx::Compile::ExtensionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/netlinx/compile/extension_handler.rb

Overview

Tells netlinx-compile which class handles the compiling of a set of file extensions.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ExtensionHandler) initialize(**kvargs)

Parameters:

extensions: An array of file extensions (without the leading dot)
            that this ExtensionHandler supports.

usurps:     Future.
            Lets this ExtensionHandler take priority over other
            ones. For example, most third-party handlers would
            probably usurp the .apw NetLinx Studio workspace
            extension.

is_a_workspace: Set to true if this ExtensionHandler is for
            compiling a workspace. False by default. This
            parameter assists with smart compiling, as
            ExtensionDiscovery can return all workspace_handlers.

handler_class: A reference to the class that should be instantiated
            if this handler is selected. For example,
            NetLinx::SourceFile is the class that handles files
            with the .axs extension.


37
38
39
40
41
42
# File 'lib/netlinx/compile/extension_handler.rb', line 37

def initialize(**kvargs)
  @extensions     = kvargs.fetch :extensions,     []
  @usurps         = kvargs.fetch :usurps,         []
  @is_a_workspace = kvargs.fetch :is_a_workspace, false
  @handler_class  = kvargs.fetch :handler_class,  nil
end

Instance Attribute Details

- (Object) extensions

A list of file extensions that this ExtensionHandler handles.



7
8
9
# File 'lib/netlinx/compile/extension_handler.rb', line 7

def extensions
  @extensions
end

- (Object) handler_class (readonly)

The class to invoke to handle compiling a file extension specified in this ExtensionHandler.



16
17
18
# File 'lib/netlinx/compile/extension_handler.rb', line 16

def handler_class
  @handler_class
end

- (Object) usurps

A list of file extensions that this ExtensionHandler usurps. For example, third-party workspace extensions would probably usurp the .apw workspace extension.



12
13
14
# File 'lib/netlinx/compile/extension_handler.rb', line 12

def usurps
  @usurps
end

Instance Method Details

- (Object) <<(file_extension)

Alias to add a file extension.



45
46
47
# File 'lib/netlinx/compile/extension_handler.rb', line 45

def <<(file_extension)
  @extensions << parse_extension(file_extension)
end

- (Boolean) include?(file_extension)

Returns true if this ExtensionHandler can handle the specified file extension.

Returns:

  • (Boolean)


64
65
66
# File 'lib/netlinx/compile/extension_handler.rb', line 64

def include?(file_extension)
  @extensions.include? parse_extension(file_extension)
end

- (Boolean) is_a_workspace?

Returns true if the ExtensionHandler handles a workspace file (as opposed to a source code file).

Workspace files are significant because they contain information about a project, connection settings for a master, and possibly multiple systems that need to be compiled. Therefore, when smart-compiling, workspaces need to be distinguished from source code files because discovering a workspace should be considered a better match than discovering a source code file.

Returns:

  • (Boolean)


58
59
60
# File 'lib/netlinx/compile/extension_handler.rb', line 58

def is_a_workspace?
  @is_a_workspace
end