Class: Dentaku::AST::Enum

Inherits:
Function show all
Defined in:
lib/dentaku/ast/functions/enum.rb

Direct Known Subclasses

All, Any, Filter, Map, Pluck

Constant Summary

Constants inherited from Function

Function::DIG

Instance Attribute Summary

Attributes inherited from Function

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#accept, get, #initialize, numeric, register, register_class, registry

Methods inherited from Node

arity, #name, peek, precedence, #type

Constructor Details

This class inherits a constructor from Dentaku::AST::Function

Class Method Details

.max_param_countObject



11
12
13
# File 'lib/dentaku/ast/functions/enum.rb', line 11

def self.max_param_count
  3
end

.min_param_countObject



7
8
9
# File 'lib/dentaku/ast/functions/enum.rb', line 7

def self.min_param_count
  3
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dentaku/ast/functions/enum.rb', line 15

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

#validate_identifier(arg, message = "#{name}() requires second argument to be an identifier") ⇒ Object



30
31
32
33
34
# File 'lib/dentaku/ast/functions/enum.rb', line 30

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