Class: LEWT::Extension

Inherits:
Object
  • Object
show all
Defined in:
lib/extension.rb

Constant Summary collapse

@@lewt_extensions =

@@extensions is a registry shared between all extensions that impliment this class containing there class names for invocation by the core system.

Array.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ext_init = { :cmd => "lewt_base_extension" }) ⇒ Extension

This method is inoked by subclasses to initialise themselves within Lewt’s extension registry.

ext_init [Hash]

contains the keys :cmd, :options - which are the command name (String) and options (Hash) for the extension respectively.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/extension.rb', line 29

def initialize ( ext_init = { :cmd => "lewt_base_extension" } )
  core_settings = YAML.load_file( File.expand_path( '../config/settings.yml', __FILE__) )
  if File.exists? File.expand_path( '~/.lewt_settings', __FILE__)
    core_settings.merge! YAML.load_file( File.expand_path( '~/.lewt_settings', __FILE__) )
  end

  @lewt_stash = core_settings['lewt_stash'] || File.expand_path('../', __FILE__) + "/config/"
  load_lewt_settings()
  @command_name = ext_init[:cmd]
  @options = ext_init[:options] || nil
  register_extension
end

Instance Attribute Details

#command_nameObject (readonly)

LEWT Stash is the user configured stash path where all extensions, config file, templates etc are stored.



20
21
22
# File 'lib/extension.rb', line 20

def command_name
  @command_name
end

#customersObject (readonly)

LEWT Stash is the user configured stash path where all extensions, config file, templates etc are stored.



20
21
22
# File 'lib/extension.rb', line 20

def customers
  @customers
end

#enterpriseObject (readonly)

LEWT Stash is the user configured stash path where all extensions, config file, templates etc are stored.



20
21
22
# File 'lib/extension.rb', line 20

def enterprise
  @enterprise
end

#lewt_settingsObject (readonly)

LEWT Stash is the user configured stash path where all extensions, config file, templates etc are stored.



20
21
22
# File 'lib/extension.rb', line 20

def lewt_settings
  @lewt_settings
end

#lewt_stashObject (readonly)

LEWT Stash is the user configured stash path where all extensions, config file, templates etc are stored.



20
21
22
# File 'lib/extension.rb', line 20

def lewt_stash
  @lewt_stash
end

#optionsObject (readonly)

LEWT Stash is the user configured stash path where all extensions, config file, templates etc are stored.



20
21
22
# File 'lib/extension.rb', line 20

def options
  @options
end

Instance Method Details

#get_matched_customers(query, suppress = nil) ⇒ Object

This method mathes customers wth query strings provided by users in the CLI

query [String]

A search string to query against.

suppress [String]

A list of clients to exclude. Defaults to nil ie: none.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/extension.rb', line 50

def get_matched_customers( query, suppress = nil )
  requestedClients = Array.new
  if query == nil
    @customers.each do |client|
      client_match = [ client["alias"], client["name"] ].join("|")
      if suppress == nil or client_match.match(suppress.gsub(Lewt::OPTION_DELIMITER_REGEX,"|")) == nil
        requestedClients.push(client)
      end
    end
  else
    @customers.each do |client|
      client_match = [ client["alias"], client["name"] ].join("|")
      if client_match.match( query.gsub(Lewt::OPTION_DELIMITER_REGEX,"|") ) != nil
        if suppress == nil or client_match.match(suppress.gsub(Lewt::OPTION_DELIMITER_REGEX,"|")) == nil
          requestedClients.push(client)
        end
      end
    end
  end
  return requestedClients
end

#lewt_extensionsObject

returns all registered extensions as an array of class names



43
44
45
# File 'lib/extension.rb', line 43

def lewt_extensions
  @@lewt_extensions
end