Class: Twig::Callable

Inherits:
Object
  • Object
show all
Defined in:
lib/twig/callable.rb

Direct Known Subclasses

TwigFilter, TwigFunction, TwigTest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, callable = nil, options = {}) ⇒ Callable

Returns a new instance of Callable.

Parameters:

  • name (String)
  • callable (Proc|Nil) (defaults to: nil)
  • options (Hash) (defaults to: {})


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/twig/callable.rb', line 11

def initialize(name, callable = nil, options = {})
  @name = @dynamic_name = name
  @arguments = []
  @callable = callable
  @options = {
    needs_environment: false,
    needs_context: false,
    needs_charset: false,
    is_variadic: false,
  }.merge(options)
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



6
7
8
# File 'lib/twig/callable.rb', line 6

def arguments
  @arguments
end

#callableObject (readonly)

Returns the value of attribute callable.



5
6
7
# File 'lib/twig/callable.rb', line 5

def callable
  @callable
end

#dynamic_nameObject

Returns the value of attribute dynamic_name.



6
7
8
# File 'lib/twig/callable.rb', line 6

def dynamic_name
  @dynamic_name
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/twig/callable.rb', line 6

def name
  @name
end

Instance Method Details

#needs_charset?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/twig/callable.rb', line 27

def needs_charset?
  @options[:needs_charset]
end

#needs_context?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/twig/callable.rb', line 35

def needs_context?
  @options[:needs_context]
end

#needs_environment?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/twig/callable.rb', line 31

def needs_environment?
  @options[:needs_environment]
end

#typeObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/twig/callable.rb', line 23

def type
  raise NotImplementedError
end

#with_dynamic_arguments(name, dynamic_name, arguments) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/twig/callable.rb', line 39

def with_dynamic_arguments(name, dynamic_name, arguments)
  new = clone
  new.name = name
  new.dynamic_name = dynamic_name
  new.arguments = arguments

  new
end