Class: Gloo::Objs::Script

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

Constant Summary collapse

KEYWORD =
'script'.freeze
KEYWORD_SHORT =
'cmd'.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, #add_children_on_create?, #add_default_children, 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, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #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

.doc_dataObject

Get the object's documentation data.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/gloo/objs/basic/script.rb', line 104

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'An executable script — a set of commands to be run.',
    :messages => [
      'run — Run the script. The script can be run by telling the ' \
        'object to run, or via the run verb.'
    ],
    :examples => <<~EXAMPLES.strip
      script [can] :
        on_load [script] :
          show "Showing multiple lines..."
          show script.msg1
          show script.msg2
          show script.msg3
          show "Done."
        msg1 [string] : one
        msg2 [string] : two
        msg3 [string] : three
    EXAMPLES
  }
end

.messagesObject

Get a list of message names that this object receives.



85
86
87
# File 'lib/gloo/objs/basic/script.rb', line 85

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

.short_typenameObject

The short name of the object type.



25
26
27
# File 'lib/gloo/objs/basic/script.rb', line 25

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



18
19
20
# File 'lib/gloo/objs/basic/script.rb', line 18

def self.typename
  return KEYWORD
end

Instance Method Details

#add_line(line) ⇒ Object

Add a line (cmd) to the script.



46
47
48
49
50
51
52
53
54
55
# File 'lib/gloo/objs/basic/script.rb', line 46

def add_line( line )
  if self.value_string?
    first = self.value
    self.set_array_value []
    self.value << first unless first.empty?
  elsif self.value_is_blank?
    self.set_array_value []
  end
  self.value << line.strip
end

#line_countObject

Get the number of lines in this script.



68
69
70
71
72
73
74
75
76
# File 'lib/gloo/objs/basic/script.rb', line 68

def line_count
  return self.value.count if self.value_is_array?

  if self.value_string?
    return self.value.strip.empty? ? 0 : 1
  end

  return 0
end

#msg_runObject

Send the object the unload message.



92
93
94
95
# File 'lib/gloo/objs/basic/script.rb', line 92

def msg_run
  s = Gloo::Exec::Script.new( @engine, self )
  s.run
end

#multiline_value?Boolean

Does this object support multi-line values? Initially only true for scripts.

Returns:



61
62
63
# File 'lib/gloo/objs/basic/script.rb', line 61

def multiline_value?
  return true
end

#set_array_value(arr) ⇒ Object

Set the value as an array.



39
40
41
# File 'lib/gloo/objs/basic/script.rb', line 39

def set_array_value( arr )
  self.value = arr
end

#set_value(new_value) ⇒ Object

Set the value with any necessary type conversions.



32
33
34
# File 'lib/gloo/objs/basic/script.rb', line 32

def set_value( new_value )
  self.value = new_value.to_s
end