Class: Gloo::Core::GlooSystem

Inherits:
Obj
  • Object
show all
Defined in:
lib/gloo/core/gloo_system.rb

Constant Summary collapse

KEYWORD =
'gloo'.freeze
KEYWORD_SHORT =
'$'.freeze

Constants inherited from Baseo

Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary collapse

Attributes inherited from Obj

#children, #parent

Attributes inherited from Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Obj

#add_child, #add_default_children, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_responds_to?, #msg_unload, #multiline_value?, #remove_child, #render, #send_message, #set_parent, #sql_value

Constructor Details

#initialize(engine, pn) ⇒ GlooSystem

Set up the object.



21
22
23
24
# File 'lib/gloo/core/gloo_system.rb', line 21

def initialize( engine, pn )
  @engine = engine
  @pn = pn
end

Instance Attribute Details

#pnObject (readonly)

Returns the value of attribute pn.



18
19
20
# File 'lib/gloo/core/gloo_system.rb', line 18

def pn
  @pn
end

Class Method Details

.can_create?Boolean

Can this object be created? This is true by default and only false for some special cases such as the System object.

Returns:

  • (Boolean)


55
56
57
# File 'lib/gloo/core/gloo_system.rb', line 55

def self.can_create?
  false
end

.doc_dataObject

Get the object's documentation data.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/gloo/core/gloo_system.rb', line 295

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'The gloo system objects are virtual objects — ' \
      "accessed like other objects (via 'gloo' or the shortcut " \
      '$), but their values are set by the system and cannot be ' \
      'updated. They also do not show up in the object heap. Some ' \
      'names include an underscore to separate words; a period ' \
      'can be used instead, so gloo.working_dir and ' \
      'gloo.working.dir are identical.',
    :children => [
      'app — Path of the running app (same as gloo_projects).',
      'hostname — Get the system hostname.',
      'user — Get the logged in user.',
      'line — A carriage return (line feed) character.',
      "user_home — Get the user's home directory.",
      'working_dir — Get the working directory.',
      'gloo_home — Get the gloo home directory.',
      'gloo_config — Get the gloo configuration directory.',
      'gloo_projects — Get the gloo projects directory.',
      'gloo_log — Get the gloo logging directory.',
      'screen_lines — Get the number of lines on screen.',
      'screen_cols — Get the number of columns on screen.',
      'platform_cpu — Get the platform CPU.',
      'platform_os — Get the platform operating system.',
      'platform_version — Get the platform version.',
      'platform_windows? — Is the platform Windows?',
      'platform_unix? — Is the platform Unix?',
      'platform_linux? — Is the platform Linux?',
      'platform_mac? — Is the platform Mac?'
    ],
    :examples => <<~EXAMPLES.strip
      > show gloo.user
      > show $.user

      > show gloo.working_dir
      > show gloo.working.dir
      > show $.working_dir
      > show $.working.dir
    EXAMPLES
  }
end

.messagesObject

Get a list of message names that this object receives.



134
135
136
# File 'lib/gloo/core/gloo_system.rb', line 134

def self.messages
  return []
end

.open_for_platformObject

Get the command to open a file on this platform.



278
279
280
281
282
283
284
285
286
# File 'lib/gloo/core/gloo_system.rb', line 278

def self.open_for_platform
  return 'open' if OS.mac?
  return 'xdg-open' if OS.posix?

  return 'Start-Process' if OS.windows?
  return 'explorer.exe' if self.wsl?

  return nil
end

.short_typenameObject

The short name of the object type.



36
37
38
# File 'lib/gloo/core/gloo_system.rb', line 36

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



29
30
31
# File 'lib/gloo/core/gloo_system.rb', line 29

def self.typename
  return KEYWORD
end

.wsl?Boolean

Is the platform WSL on Windows?

Returns:

  • (Boolean)


265
266
267
268
269
270
271
272
273
# File 'lib/gloo/core/gloo_system.rb', line 265

def self.wsl?
  return false unless OS.linux?

  ENV.key?('WSL_DISTRO_NAME') ||
    ENV.key?('WSL_INTEROP') ||
    File.read('/proc/sys/kernel/osrelease').downcase.include?('microsoft')
rescue
  return false
end

Instance Method Details

#add_children_on_create?Boolean

Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.

Returns:

  • (Boolean)


122
123
124
# File 'lib/gloo/core/gloo_system.rb', line 122

def add_children_on_create?
  return false
end

#dispatch(msg) ⇒ Object

Dispatch the message and get the value.



139
140
141
142
143
144
145
# File 'lib/gloo/core/gloo_system.rb', line 139

def dispatch( msg )
  o = "msg_#{msg}"
  return self.public_send( o ) if self.respond_to? o

  @engine.err "Message #{msg} not implemented"
  return false
end

#msg_appObject

The running app directory.



183
184
185
# File 'lib/gloo/core/gloo_system.rb', line 183

def msg_app
  return @engine.settings.project_path
end

#msg_gloo_configObject

Get the Gloo configuration directory



173
174
175
# File 'lib/gloo/core/gloo_system.rb', line 173

def msg_gloo_config
  return @engine.settings.config_path
end

#msg_gloo_homeObject

Get the Gloo home directory



168
169
170
# File 'lib/gloo/core/gloo_system.rb', line 168

def msg_gloo_home
  return @engine.settings.user_root
end

#msg_gloo_logObject

Get the Gloo log directory



188
189
190
# File 'lib/gloo/core/gloo_system.rb', line 188

def msg_gloo_log
  return @engine.settings.log_path
end

#msg_gloo_projectsObject

Get the Gloo projects directory



178
179
180
# File 'lib/gloo/core/gloo_system.rb', line 178

def msg_gloo_projects
  return @engine.settings.project_path
end

#msg_hostnameObject

Get the system hostname.



148
149
150
# File 'lib/gloo/core/gloo_system.rb', line 148

def msg_hostname
  return Socket.gethostname
end

#msg_lineObject

Carriage return (line feed)



198
199
200
# File 'lib/gloo/core/gloo_system.rb', line 198

def msg_line
  return "\n"
end

#msg_platform_cpuObject

Get the platform CPU



223
224
225
# File 'lib/gloo/core/gloo_system.rb', line 223

def msg_platform_cpu
  return OS.host_cpu
end

#msg_platform_linux?Boolean

Is the platform Linux?

Returns:

  • (Boolean)


248
249
250
# File 'lib/gloo/core/gloo_system.rb', line 248

def msg_platform_linux?
  return OS.posix?
end

#msg_platform_mac?Boolean

Is the platform Mac?

Returns:

  • (Boolean)


253
254
255
# File 'lib/gloo/core/gloo_system.rb', line 253

def msg_platform_mac?
  return OS.mac?
end

#msg_platform_osObject

Get the platform Operating System



228
229
230
# File 'lib/gloo/core/gloo_system.rb', line 228

def msg_platform_os
  return RUBY_PLATFORM
end

#msg_platform_unix?Boolean

Is the platform Unix?

Returns:

  • (Boolean)


243
244
245
# File 'lib/gloo/core/gloo_system.rb', line 243

def msg_platform_unix?
  return OS.posix?
end

#msg_platform_versionObject

Get the platform version



233
234
235
# File 'lib/gloo/core/gloo_system.rb', line 233

def msg_platform_version
  return 'n/a'
end

#msg_platform_windows?Boolean

Is the platform Windows?

Returns:

  • (Boolean)


238
239
240
# File 'lib/gloo/core/gloo_system.rb', line 238

def msg_platform_windows?
  return OS.windows?
end

#msg_platform_wsl?Boolean

Is the platform WSL on Windows?

Returns:

  • (Boolean)


258
259
260
# File 'lib/gloo/core/gloo_system.rb', line 258

def msg_platform_wsl?
  return self.class.wsl?
end

#msg_screen_colsObject

Get the number of columns on screen.



213
214
215
# File 'lib/gloo/core/gloo_system.rb', line 213

def msg_screen_cols
  return Gloo::App::Settings.cols( @engine )
end

#msg_screen_linesObject

Get the number of lines on screen.



208
209
210
# File 'lib/gloo/core/gloo_system.rb', line 208

def msg_screen_lines
  return Gloo::App::Settings.lines( @engine )
end

#msg_userObject

Get the logged in User.



153
154
155
# File 'lib/gloo/core/gloo_system.rb', line 153

def msg_user
  return ENV[ 'USER' ]
end

#msg_user_homeObject

Get the user's home directory.



158
159
160
# File 'lib/gloo/core/gloo_system.rb', line 158

def msg_user_home
  return File.expand_path( '~' )
end

#msg_working_dirObject

Get the working directory.



163
164
165
# File 'lib/gloo/core/gloo_system.rb', line 163

def msg_working_dir
  return Dir.pwd
end

#paramObject

Get the parameter.



66
67
68
69
70
# File 'lib/gloo/core/gloo_system.rb', line 66

def param
  return nil unless @pn && @pn.segments.count > 1

  return @pn.segments[ 1..-1 ].join( '_' )
end

#root?Boolean

Is this the root object?

Returns:

  • (Boolean)


48
49
50
# File 'lib/gloo/core/gloo_system.rb', line 48

def root?
  return false
end

#set_value(new_value) ⇒ Object

There is no value object in the system.



82
83
84
# File 'lib/gloo/core/gloo_system.rb', line 82

def set_value( new_value )
  # overriding base functionality with dummy function
end

#type_displayObject

The object type, suitable for display.



43
44
45
# File 'lib/gloo/core/gloo_system.rb', line 43

def type_display
  return self.class.typename
end

#valueObject

Get the system value.



75
76
77
# File 'lib/gloo/core/gloo_system.rb', line 75

def value
  return dispatch param
end

#value_displayObject

Get the value for display purposes.



89
90
91
# File 'lib/gloo/core/gloo_system.rb', line 89

def value_display
  return value
end

#value_is_array?Boolean

Is the value an Array?

Returns:

  • (Boolean)


103
104
105
# File 'lib/gloo/core/gloo_system.rb', line 103

def value_is_array?
  return false
end

#value_is_blank?Boolean

Is the value a blank string?

Returns:

  • (Boolean)


110
111
112
# File 'lib/gloo/core/gloo_system.rb', line 110

def value_is_blank?
  return true
end

#value_string?Boolean

Is the value a String?

Returns:

  • (Boolean)


96
97
98
# File 'lib/gloo/core/gloo_system.rb', line 96

def value_string?
  return true
end