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, numeric, register, register_class, registry

Methods inherited from Node

arity, #name, peek, precedence, #type

Constructor Details

#initialize(*args) ⇒ Enum

Returns a new instance of Enum.



15
16
17
18
# File 'lib/dentaku/ast/functions/enum.rb', line 15

def initialize(*args)
  super
  validate_identifier(@args[1])
end

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



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dentaku/ast/functions/enum.rb', line 20

def dependencies(context = {})
  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

Raises:



33
34
35
# File 'lib/dentaku/ast/functions/enum.rb', line 33

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