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

#initialize(**kwargs) ⇒ ExtensionHandler

Returns a new instance of ExtensionHandler.

Parameters:

  • kwargs (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :extensions (Array<String>)

    File extensions (without the leading dot) that this ExtensionHandler supports.

  • :usurps (Array<String>)

    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 (Boolean)

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

  • :handler_class (Extension)

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



35
36
37
38
39
40
# 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

Instance Attribute Details

#extensionsObject

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

#handler_classObject (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

#usurpsObject

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

#<<(file_extension) ⇒ Object

Alias to add a file extension.



43
44
45
# File 'lib/netlinx/compile/extension_handler.rb', line 43

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

#include?(file_extension) ⇒ Boolean

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

Returns:

  • (Boolean)


62
63
64
# File 'lib/netlinx/compile/extension_handler.rb', line 62

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

#is_a_workspace?Boolean

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:



56
57
58
# File 'lib/netlinx/compile/extension_handler.rb', line 56

def is_a_workspace?
  @is_a_workspace
end