Sha256: c650936a478c68caf8be9c0fd161ca07d890958c713b67cf5875160912248c29

Contents?: true

Size: 734 Bytes

Versions: 2

Compression:

Stored size: 734 Bytes

Contents

require_relative '../function'
require_relative '../../exceptions'

module Dentaku
  module AST
    class All < Function
      def self.min_param_count
        3
      end

      def self.max_param_count
        3
      end

      def deferred_args
        [1, 2]
      end

      def value(context = {})
        collection      = @args[0].value(context)
        item_identifier = @args[1].identifier
        expression      = @args[2]

        Array(collection).all? do |item_value|
          expression.value(
            context.update(
              FlatHash.from_hash(item_identifier => item_value)
            )
          )
        end
      end
    end
  end
end

Dentaku::AST::Function.register_class(:all, Dentaku::AST::All)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dentaku-3.4.1 lib/dentaku/ast/functions/all.rb
dentaku-3.4.0 lib/dentaku/ast/functions/all.rb