Class: Gloo::Objs::EachFile

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/objs/ctrl/each_file.rb

Constant Summary collapse

FILE =
'file'.freeze
EXT =
'ext'.freeze
WILD =
'*'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, iterator_obj) ⇒ EachFile


Create Iterator



20
21
22
23
# File 'lib/gloo/objs/ctrl/each_file.rb', line 20

def initialize( engine, iterator_obj )
  @engine = engine
  @iterator_obj = iterator_obj
end

Class Method Details

.use_for?(iterator_obj) ⇒ Boolean

Use this iterator for each loop?

Returns:



33
34
35
36
37
# File 'lib/gloo/objs/ctrl/each_file.rb', line 33

def self.use_for?( iterator_obj )
  return true if iterator_obj.find_child FILE

  return false
end

Instance Method Details

#runObject

Run for each file.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gloo/objs/ctrl/each_file.rb', line 47

def run
  folder = @iterator_obj.in_value
  return unless folder

  unless Dir.exist?( folder )
    @engine.err "Folder does not exist: #{folder}"
  end

  Dir.glob( "#{folder}#{wildcard}" ).each do |f|
    set_file f
    @iterator_obj.run_do
  end
end

#set_file(f) ⇒ Object

Set the value of the word.



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

def set_file( f )
  o = @iterator_obj.find_child FILE
  return unless o

  o.set_value f
end

#wildcardObject

Get the wildcard for the glob.



64
65
66
67
68
69
# File 'lib/gloo/objs/ctrl/each_file.rb', line 64

def wildcard
  o = @iterator_obj.find_child EXT
  return WILD unless o

  return "#{WILD}.#{o.value}"
end