class NetLinx::Compile::ExtensionHandler

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

Attributes

extensions[RW]

A list of file extensions that this ExtensionHandler handles.

handler_class[R]

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

usurps[RW]

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

Public Class Methods

new(**kwargs) click to toggle source

@option kwargs [Array<String>] :extensions File extensions (without the

leading dot) that this ExtensionHandler supports.

@option kwargs [Array<String>] :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.

@option kwargs [Boolean] :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.

@option kwargs [Extension] :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.
# File lib/netlinx/compile/extension_handler.rb, line 35
def initialize(**kwargs)
  @extensions     = kwargs.fetch :extensions,     []
  @usurps         = kwargs.fetch :usurps,         []
  @is_a_workspace = kwargs.fetch :is_a_workspace, false
  @handler_class  = kwargs.fetch :handler_class,  nil
end

Public Instance Methods

<<(file_extension) click to toggle source

Alias to add a file extension.

# File lib/netlinx/compile/extension_handler.rb, line 43
def <<(file_extension)
  @extensions << parse_extension(file_extension)
end
include?(file_extension) click to toggle source

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

# File lib/netlinx/compile/extension_handler.rb, line 62
def include?(file_extension)
  @extensions.include? parse_extension(file_extension)
end
is_a_workspace?() click to toggle source

@return [Boolean] 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.

# File lib/netlinx/compile/extension_handler.rb, line 56
def is_a_workspace?
  @is_a_workspace
end

Private Instance Methods

parse_extension(file_extension) click to toggle source

Parse a file extension from the given string.

@example

apw
.apw
workspace.apw
c:/path/to/workspace.apw
# File lib/netlinx/compile/extension_handler.rb, line 75
def parse_extension(file_extension)
  ext = file_extension.scan(/(?:^\s*|(?<=\.))(\w+)$/).first
  raise ArgumentError, "Could not parse a file extension from the string: #{file_extension}" unless ext
  
  ext.first
end