Sha256: 085d32c20087d0420f8a0616ad6fd5abbaeaa2eae5dff168eed64db36ea0d553

Contents?: true

Size: 743 Bytes

Versions: 5

Compression:

Stored size: 743 Bytes

Contents

module Supa
  module Commands
    class Collection < Supa::Command
      def represent
        return if hide?

        define_tree
        return unless value

        value.each do |element|
          @tree[@name] << {}

          Supa::Builder.new(element,
            representer: @representer, tree: @tree[@name][-1]).instance_exec(&@block)
        end
      end

      private

      def apply_render_flags(val)
        return [] if !val && empty_when_nil?
        val
      end

      def hide?
        return hide_when_empty? unless value
        return false unless value.is_a?(Array)

        value.any? ? false : hide_when_empty?
      end

      def define_tree
        @tree[@name] = !value ? nil : []
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
supa-0.5.2 lib/supa/commands/collection.rb
supa-0.5.1 lib/supa/commands/collection.rb
supa-0.5.0 lib/supa/commands/collection.rb
supa-0.4.1 lib/supa/commands/collection.rb
supa-0.3.0 lib/supa/commands/collection.rb