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
CHILD =
'child'.freeze
WORD =
'word'.freeze
LINE =
'line'.freeze
FILE =
'file'.freeze
REPO =
'repo'.freeze
IN =
'IN'.freeze
DO =
'do'.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, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #set_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/ctrl/each.rb', line 91

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

.short_typenameObject

The short name of the object type.



36
37
38
# File 'lib/gloo/objs/ctrl/each.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/each.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:



68
69
70
# File 'lib/gloo/objs/ctrl/each.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/ctrl/each.rb', line 77

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

#each_child?Boolean

Is it set up to run for each word? If there is a child object by the name “word” then we will loop for each word in the string.

Returns:



117
118
119
120
121
# File 'lib/gloo/objs/ctrl/each.rb', line 117

def each_child?
  return true if contains_child? CHILD

  return false
end

#each_line?Boolean

Is it set up to run for each line? If there is a child object by the name “line” then we will loop for each line in the string.

Returns:



194
195
196
197
198
# File 'lib/gloo/objs/ctrl/each.rb', line 194

def each_line?
  return true if find_child LINE

  return false
end

#each_repo?Boolean

Is it set up to run for each git repo? If there is a child object by the name “repo” then we will loop for each repo in the directory.

Returns:



232
233
234
235
236
# File 'lib/gloo/objs/ctrl/each.rb', line 232

def each_repo?
  return true if find_child REPO

  return false
end

#each_word?Boolean

Is it set up to run for each word? If there is a child object by the name “word” then we will loop for each word in the string.

Returns:



156
157
158
159
160
# File 'lib/gloo/objs/ctrl/each.rb', line 156

def each_word?
  return true if find_child WORD

  return false
end

#find_all_git_projects(path) ⇒ Object

Find all git projects in a path.



241
242
243
244
245
246
247
248
249
# File 'lib/gloo/objs/ctrl/each.rb', line 241

def find_all_git_projects( path )
  path.children.collect do |f|
    if f.directory? && ( File.basename( f ) == '.git' )
      File.dirname( f )
    elsif f.directory?
      find_all_git_projects( f )
    end
  end.flatten.compact
end

#in_valueObject

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



44
45
46
47
# File 'lib/gloo/objs/ctrl/each.rb', line 44

def in_value
  o = find_child IN
  return o ? o.value : nil
end

#msg_runObject

Run the system command.



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

def msg_run
  if each_child?
    run_each_child
  elsif each_word?
    run_each_word
  elsif each_line?
    run_each_line
  elsif each_repo?
    run_each_repo
  end
end

#run_doObject

Run the do script once.



52
53
54
55
56
57
# File 'lib/gloo/objs/ctrl/each.rb', line 52

def run_do
  o = find_child DO
  return unless o

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

#run_each_childObject

Run for each word.



126
127
128
129
130
131
132
133
134
135
# File 'lib/gloo/objs/ctrl/each.rb', line 126

def run_each_child
  o = find_child IN
  return unless o

  o = Gloo::Objs::Alias.resolve_alias( @engine, o )
  o.children.each do |child|
    set_child child
    run_do
  end
end

#run_each_lineObject

Run for each line.



203
204
205
206
207
208
209
210
211
# File 'lib/gloo/objs/ctrl/each.rb', line 203

def run_each_line
  str = in_value
  return unless str

  str.each_line do |line|
    set_line line
    run_do
  end
end

#run_each_repoObject

Run for each line.



254
255
256
257
258
259
260
261
262
263
264
# File 'lib/gloo/objs/ctrl/each.rb', line 254

def run_each_repo
  path = in_value
  return unless path

  path = Pathname.new( path )
  repos = find_all_git_projects( path )
  repos.each do |o|
    set_repo o
    run_do
  end
end

#run_each_wordObject

Run for each word.



165
166
167
168
169
170
171
172
173
# File 'lib/gloo/objs/ctrl/each.rb', line 165

def run_each_word
  str = in_value
  return unless str

  str.split( ' ' ).each do |word|
    set_word word
    run_do
  end
end

#set_child(obj) ⇒ Object

Set the child alias.



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

def set_child( obj )
  o = find_child CHILD
  return unless o

  o.set_value obj.pn
end

#set_line(line) ⇒ Object

Set the value of the word.



216
217
218
219
220
221
# File 'lib/gloo/objs/ctrl/each.rb', line 216

def set_line( line )
  o = find_child LINE
  return unless o

  o.set_value line
end

#set_repo(path) ⇒ Object

Set the value of the repo. This is a path to the repo.



270
271
272
273
274
275
# File 'lib/gloo/objs/ctrl/each.rb', line 270

def set_repo( path )
  o = find_child REPO
  return unless o

  o.set_value path
end

#set_word(word) ⇒ Object

Set the value of the word.



178
179
180
181
182
183
# File 'lib/gloo/objs/ctrl/each.rb', line 178

def set_word( word )
  o = find_child WORD
  return unless o

  o.set_value word
end