Sha256: e0681b4e79b022f5f534a871c3dc527dcb6805d329435123a65573e782483623

Contents?: true

Size: 1.3 KB

Versions: 43

Compression:

Stored size: 1.3 KB

Contents

module Redcar
  class Runnables
    class RunnableGroup
      include Redcar::Tree::Mirror::NodeMirror
      attr_reader :text

      def initialize(name, path, runnables)
        @text      = name
        @runnables = []
        @subgroups = {}
        runnables.each do |runnable|
          if runnable["type"].nil? or runnable["type"].empty?
            @runnables << Runnable.new(runnable["name"], path, runnable)
          else
            type_group(runnable["type"]).add_runnable Runnable.new(runnable["name"], path, runnable)
          end
        end
      end

      def leaf?
        false
      end

      def icon
        :file
      end

      # Sort the subgroups first, the runnables after that
      def children
        @children ||= (@subgroups.sort_by(&:first).collect(&:last) + @runnables.sort_by(&:text))
      end

      # Return the type group that corresponds to the passed name-path, or self, if name is empty
      # If a child with the specified path does not exist, create it and clear the children cache
      def type_group(name)
        names = name.split("/")
        unless @subgroups[names.first]
          @children = nil
          @subgroups[names.first] = RunnableTypeGroup.new(names.first)
        end
        @subgroups[names.first].type_group(names[1..-1].join)
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
redcar-0.13 plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.13.5dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.13.4dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.13.3dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.13.2dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.13.1dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-0.12.1 plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.13.0dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-0.12 plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.27dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.26dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.25dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.24dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.23dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.22dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.21dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.20dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.19dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.18dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb
redcar-dev-0.12.17dev plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb