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_responds_to?, #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.



91
92
93
# File 'lib/gloo/objs/system/system.rb', line 91

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:



68
69
70
# File 'lib/gloo/objs/system/system.rb', line 68

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.



77
78
79
80
81
82
# File 'lib/gloo/objs/system/system.rb', line 77

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 command from the child object. Returns nil if there is none.



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

def cmd_value
  return find_child_value CMD
end

#msg_runObject

Run the system command.



98
99
100
101
102
103
104
# File 'lib/gloo/objs/system/system.rb', line 98

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:



55
56
57
# File 'lib/gloo/objs/system/system.rb', line 55

def output?
  return find_child_value GET_OUTPUT
end

#run_with_outputObject

Run the command and collect output.



109
110
111
112
113
114
115
# File 'lib/gloo/objs/system/system.rb', line 109

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.



120
121
122
123
124
125
126
# File 'lib/gloo/objs/system/system.rb', line 120

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.



43
44
45
46
47
48
# File 'lib/gloo/objs/system/system.rb', line 43

def set_result( data )
  r = find_child_resolve_alias RESULT
  return unless r

  r.set_value data
end