Class: Gloo::Verbs::Load

Inherits:
Core::Verb show all
Defined in:
lib/gloo/verbs/load.rb

Constant Summary collapse

KEYWORD =
'load'.freeze
KEYWORD_SHORT =
'ld'.freeze
MISSING_EXPR_ERR =
'Missing Expression!'.freeze
UNKNOWN_OPT_ERR =
'Unknown load option!'.freeze
WRONG_NUM_ARGS_ERR =
'Wrong number of arguments! 2 or 3 expected.'.freeze
FEATURE_NOT_IMPLEMENTED_ERR =
'Feature not implemented yet!'.freeze
FILE_OPT =
'file'.freeze
EXT_OPT =
'ext'.freeze
LIB_OPT =
'lib'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Verb

#params, #tokens

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Verb

#display_value, help, inherited, #initialize, #type_display

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Verb

Class Method Details

.doc_dataObject

Get the verb's documentation data.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/gloo/verbs/load.rb', line 95

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'Load an object file. There are two ways to ' \
      'specify the file. Give either the full path and file name ' \
      'or use a relative path from the gloo project folder. For ' \
      'the latter, the extension is not needed. For the former, ' \
      'the file extension is necessary. Using * instead of a file ' \
      'name will load all gloo files in the folder. When using the ' \
      '--app option, the file is loaded from the application ' \
      'folder, but if not found there, the loader will also look ' \
      'in the gloo root folder. The load verb is also used to ' \
      'import an extension or library at runtime.',
    :syntax => [
      'load {file_name}',
      'load ext {my_ext}',
      'load lib {lib_name}'
    ],
    :parameters => [
      '{file_name} — Name of the object file that is to be loaded.',
      'reference type — By default, the type is file. File can be ' \
        'specified, but does not need to be. Use ext to load a ' \
        'User Extension. Use lib to load a Core Library.'
    ],
    :result => 'Objects are loaded into the heap. on_load scripts ' \
      'are run within the loaded objects.',
    :errors => [
      "#{MISSING_EXPR_ERR} — No expression is provided as parameter to the verb.",
      "#{UNKNOWN_OPT_ERR} — The reference type given isn't file, ext, or lib.",
      "#{WRONG_NUM_ARGS_ERR} — load expects 2 or 3 arguments (the verb, an optional reference type, and the file/ext/lib name)."
    ],
    :examples => <<~EXAMPLES.strip
      > load my/project/file
      > load my/app/*
      > load ~/.my_app/settings.gloo

      # Load a User Extension
      > load ext my_ext

      # Load a Core Library
      > load lib db
    EXAMPLES
  }
end

.keywordObject

Get the Verb's keyword.



53
54
55
# File 'lib/gloo/verbs/load.rb', line 53

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb's keyword shortcut.



60
61
62
# File 'lib/gloo/verbs/load.rb', line 60

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#load_extension(name) ⇒ Object

Load an extension



75
76
77
78
# File 'lib/gloo/verbs/load.rb', line 75

def load_extension( name )
  @engine.log.debug "Getting ready to load extension: #{name}"
  @engine.ext_manager.load_ext name
end

#load_gloo_file(fn) ⇒ Object

Load a gloo file



67
68
69
70
# File 'lib/gloo/verbs/load.rb', line 67

def load_gloo_file( fn )
  @engine.log.debug "Getting ready to load gloo file: #{fn}"
  @engine.persist_man.load fn
end

#load_library(name) ⇒ Object

Load a library



83
84
85
86
# File 'lib/gloo/verbs/load.rb', line 83

def load_library( name )
  @engine.log.debug "Getting ready to load library: #{name}"
  @engine.lib_manager.load_lib name
end

#runObject

Run the verb.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gloo/verbs/load.rb', line 25

def run
  if @tokens.token_count == 2
    opt = FILE_OPT
    fn = @tokens.second
  elsif @tokens.token_count == 3
    opt = @tokens.second.strip.downcase
    fn = @tokens.last
  else
    @engine.err WRONG_NUM_ARGS_ERR
    return
  end

  if fn.blank?
    @engine.err MISSING_EXPR_ERR
  elsif opt == FILE_OPT
    load_gloo_file fn
  elsif opt == EXT_OPT
    load_extension fn
  elsif opt == LIB_OPT
    load_library fn
  else 
    @engine.err UNKNOWN_OPT_ERR
  end
end