Class: Gloo::Objs::System

Inherits:
Core::Obj show all
Defined in:
lib/gloo/objs/system/system.rb

Constant Summary collapse

KEYWORD =
'system'.freeze
KEYWORD_SHORT =
'sys'.freeze
CMD =
'command'.freeze
DEFAULT_CMD =
'date'.freeze
RESULT =
'result'.freeze
GET_OUTPUT =
'get_output'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Obj

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Obj

#add_child, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #set_value, #sql_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

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

Class Method Details

.messagesObject

Get a list of message names that this object receives.



97
98
99
# File 'lib/gloo/objs/system/system.rb', line 97

def self.messages
  return super + [ 'run' ]
end

.short_typenameObject

The short name of the object type.



28
29
30
# File 'lib/gloo/objs/system/system.rb', line 28

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



21
22
23
# File 'lib/gloo/objs/system/system.rb', line 21

def self.typename
  return KEYWORD
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:



74
75
76
# File 'lib/gloo/objs/system/system.rb', line 74

def add_children_on_create?
  return true
end

#add_default_childrenObject

Add children to this object. This is used by containers to add children needed for default configurations.



83
84
85
86
87
88
# File 'lib/gloo/objs/system/system.rb', line 83

def add_default_children
  fac = @engine.factory
  fac.create_string CMD, DEFAULT_CMD, self
  fac.create_bool GET_OUTPUT, true, self
  fac.create_string RESULT, nil, self
end

#cmd_valueObject

Get the URI from the child object. Returns nil if there is none.



36
37
38
39
40
41
# File 'lib/gloo/objs/system/system.rb', line 36

def cmd_value
  cmd = find_child CMD
  return nil unless cmd

  return cmd.value
end

#msg_runObject

Run the system command.



104
105
106
107
108
109
110
# File 'lib/gloo/objs/system/system.rb', line 104

def msg_run
  if output?
    run_with_output
  else
    run_with_result
  end
end

#output?Boolean

Should the system call get output? If so, the system call will run and get output, otherwise it will just get the result of the call.

Returns:



58
59
60
61
62
63
# File 'lib/gloo/objs/system/system.rb', line 58

def output?
  o = find_child GET_OUTPUT
  return false unless o

  return o.value
end

#run_with_outputObject

Run the command and collect output.



115
116
117
118
119
120
121
# File 'lib/gloo/objs/system/system.rb', line 115

def run_with_output
  cmd = cmd_value
  return unless cmd

  result = `#{cmd}`
  set_result result
end

#run_with_resultObject

Run the command and set the result.



126
127
128
129
130
131
132
# File 'lib/gloo/objs/system/system.rb', line 126

def run_with_result
  cmd = cmd_value
  return unless cmd

  result = system cmd
  set_result result
end

#set_result(data) ⇒ Object

Set the result of the system call.



46
47
48
49
50
51
# File 'lib/gloo/objs/system/system.rb', line 46

def set_result( data )
  r = find_child RESULT
  return nil unless r

  r.set_value data
end