Sha256: a75ff718d03bb138ca8bb1b09d8b29ebc452c834e2db0c7a931e9c6ea9e671e3

Contents?: true

Size: 969 Bytes

Versions: 3

Compression:

Stored size: 969 Bytes

Contents

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

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

      def self.max_param_count
        3
      end

      def dependencies(context = {})
        validate_identifier(@args[1])

        collection      = @args[0]
        item_identifier = @args[1].identifier
        expression      = @args[2]

        collection_deps = collection.dependencies(context)
        expression_deps = (expression&.dependencies(context) || []).reject do |i|
          i == item_identifier || i.start_with?("#{item_identifier}.")
        end

        collection_deps + expression_deps
      end

      def validate_identifier(arg, message = "#{name}() requires second argument to be an identifier")
        unless arg.is_a?(Identifier)
          raise ArgumentError.for(:incompatible_type, value: arg, for: Identifier), message
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
dentaku_zevo-3.5.2 lib/dentaku/ast/functions/enum.rb
dentaku-3.5.1 lib/dentaku/ast/functions/enum.rb
dentaku-3.5.0 lib/dentaku/ast/functions/enum.rb