Class: Gloo::Objs::Each

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

Constant Summary collapse

KEYWORD =
'each'.freeze
KEYWORD_SHORT =
'each'.freeze
WORD =
'word'.freeze
DO =
'do'.freeze
IN =
'IN'.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

.doc_dataObject

Get the object's documentation data.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/gloo/objs/ctrl/each.rb', line 119

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'Perform an action for each item in a ' \
      'collection. There are several variations on this object ' \
      'type, determined by which named child is present: each ' \
      'child object in a container, each word in a string, each ' \
      'line in a block of text, each file in a folder, or each ' \
      'directory in a folder.',
    :children => [
      'in — The collection or source to iterate over (a container, string, or folder path, depending on variation).',
      'do (script) — The action to perform for each item in the loop.',
      'One of the following, whose presence determines which kind of loop this is:',
      'child (alias) — iterate a container\'s children.',
      'word (string) — iterate the words in a string.',
      'line (string) — iterate the lines in a block of text.',
      'file (file) — iterate the files in a folder; an optional ext (string) child limits to files of that extension.',
      'dir (file) — iterate the directories in a folder.'
    ],
    :messages => [
      'run — Run the loop for each item in the collection.'
    ],
    :notes => 'When iterating a container\'s children, an ' \
      'optional group_by feature is available: add a group_by ' \
      '(string) child naming a property of each child, plus ' \
      'on_group_start / on_group_end (script) children — those ' \
      'scripts run whenever the group_by value changes, letting ' \
      'you aggregate results in groups.',
    :examples => <<~EXAMPLES.strip
      #
      # Show each child in a container.
      #
      each_child [can] :

      # Iterator on children of a container.
        for [each] :
          child [alias] :
          in [alias] : each_child.objs
          do [script] : show ^.child

        # Data
        objs [can] :
          1 [string] : one
          2 [string] : two
          3 [string] : three

        # Run the iterator.
        on_load [script] :
          show 'showing children in container' (white)
          tell each_child.for to run
    EXAMPLES
  }
end

.messagesObject

Get a list of message names that this object receives.



89
90
91
# File 'lib/gloo/objs/ctrl/each.rb', line 89

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

.short_typenameObject

The short name of the object type.



33
34
35
# File 'lib/gloo/objs/ctrl/each.rb', line 33

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



26
27
28
# File 'lib/gloo/objs/ctrl/each.rb', line 26

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:



65
66
67
# File 'lib/gloo/objs/ctrl/each.rb', line 65

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.



74
75
76
77
78
79
# File 'lib/gloo/objs/ctrl/each.rb', line 74

def add_default_children
  fac = @engine.factory
  fac.create_string WORD, '', self
  fac.create_string IN, '', self
  fac.create_script DO, '', self
end

#in_valueObject

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



41
42
43
# File 'lib/gloo/objs/ctrl/each.rb', line 41

def in_value
  return find_child_value IN
end

#msg_runObject

Run the system command.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/gloo/objs/ctrl/each.rb', line 94

def msg_run
  if EachChild.use_for?( self )
    EachChild.new( @engine, self ).run
  elsif EachWord.use_for?( self )
    EachWord.new( @engine, self ).run
  elsif EachLine.use_for?( self )
    EachLine.new( @engine, self ).run
  elsif EachFile.use_for?( self )
    EachFile.new( @engine, self ).run
  elsif EachDir.use_for?( self )
    EachDir.new( @engine, self ).run
  # elsif EachRepo.use_for?( self )
  #   EachRepo.new( @engine, self ).run
  else
    @engine.err "Not set up to run each for that target."
  end
end

#run_doObject

Run the do script once.



48
49
50
51
52
53
# File 'lib/gloo/objs/ctrl/each.rb', line 48

def run_do
  o = find_child DO
  return unless o

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