Class: Gloo::Objs::Function

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

Constant Summary collapse

KEYWORD =
'function'.freeze
KEYWORD_SHORT =
'ƒ'.freeze
ON_INVOKE =

Events

'on_invoke'.freeze
AFTER_INVOKE =
'after_invoke'.freeze
PARAMS =

Parameters to the function invocation.

'params'.freeze
RESULT =

Return Value or container of objects

'result'.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_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #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.



109
110
111
# File 'lib/gloo/objs/ctrl/function.rb', line 109

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

.short_typenameObject

The short name of the object type.



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

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



29
30
31
# File 'lib/gloo/objs/ctrl/function.rb', line 29

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:



84
85
86
# File 'lib/gloo/objs/ctrl/function.rb', line 84

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.



93
94
95
96
97
98
99
# File 'lib/gloo/objs/ctrl/function.rb', line 93

def add_default_children
  fac = @engine.factory

  fac.create_can PARAMS, self
  fac.create_script ON_INVOKE, '', self
  fac.create_untyped RESULT, '', self
end

#invoke(args) ⇒ Object

Invoke the function, run the script and return the result.



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/gloo/objs/ctrl/function.rb', line 154

def invoke args
  @engine.log.debug "Invoking function: #{name}"

  set_params args if args
  run_on_invoke
  return_value = result
  @engine.heap.it.set_to return_value
  run_after_invoke
  
  return return_value
end

#msg_invokeObject

Send the object the invoke message. Invoke the functdion and return the result.



117
118
119
# File 'lib/gloo/objs/ctrl/function.rb', line 117

def msg_invoke
  return invoke( nil )
end

#multiline_value?Boolean

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

Returns:



58
59
60
# File 'lib/gloo/objs/ctrl/function.rb', line 58

def multiline_value?
  return false
end

#resultObject

Get the result, the return value or container of objects.



65
66
67
68
69
70
71
72
# File 'lib/gloo/objs/ctrl/function.rb', line 65

def result
  return_any = find_child RESULT

  # TODO: what does it look like to return objects?
  # if return_any is a container with children, return the container

  return return_any ? return_any.value : nil
end

#run_after_invokeObject

Run the after invoke script if there is one.



139
140
141
142
143
144
# File 'lib/gloo/objs/ctrl/function.rb', line 139

def run_after_invoke
  o = find_child AFTER_INVOKE
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#run_on_invokeObject

Run the on invoke script if there is one.



129
130
131
132
133
134
# File 'lib/gloo/objs/ctrl/function.rb', line 129

def run_on_invoke
  o = find_child ON_INVOKE
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#set_array_value(arr) ⇒ Object

Set the value as an array.



50
51
52
# File 'lib/gloo/objs/ctrl/function.rb', line 50

def set_array_value( arr )
  self.value = arr
end

#set_params(args) ⇒ Object

Set parameters from the arguments given.



169
170
171
172
173
174
175
176
177
# File 'lib/gloo/objs/ctrl/function.rb', line 169

def set_params args
  params = find_child PARAMS
  return unless params

  args.each_with_index do |arg, i|
    param = params.children[i]
    param.value = arg if param
  end
end

#set_value(new_value) ⇒ Object

Set the value with any necessary type conversions.



43
44
45
# File 'lib/gloo/objs/ctrl/function.rb', line 43

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