Sha256: 25d0b550fc8681c022bdc61383c778d16477a4b1f0c6b08257b23dd483163970

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2024 Eric Crane.  All rights reserved.
#
# Iterate over each child in an object container.
# 

module Gloo
  module Objs
    class EachChild

      CHILD = 'child'.freeze
      IN = 'IN'.freeze
      
      # ---------------------------------------------------------------------
      #    Create Iterator
      # ---------------------------------------------------------------------

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


      # ---------------------------------------------------------------------
      #    Check if this is the right iterator
      # ---------------------------------------------------------------------

      #
      # Use this iterator for each loop?
      #
      def self.use_for?( iterator_obj )
        return true if iterator_obj.find_child CHILD

        return false
      end


      # ---------------------------------------------------------------------
      #    Iterate
      # ---------------------------------------------------------------------

      #
      # Run for each child.
      #
      def run
        o = @iterator_obj.find_child IN
        return unless o

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

      #
      # Set the child alias.
      #
      def set_child( obj )
        o = @iterator_obj.find_child CHILD
        return unless o

        o.set_value obj.pn
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gloo-3.7.0 lib/gloo/objs/ctrl/each_child.rb
gloo-3.6.2 lib/gloo/objs/ctrl/each_child.rb
gloo-3.6.1 lib/gloo/objs/ctrl/each_child.rb
gloo-3.6.0 lib/gloo/objs/ctrl/each_child.rb