Class: Trestle::Navigation::Block::Evaluator

Inherits:
Object
  • Object
show all
Includes:
EvaluationContext
Defined in:
lib/trestle/navigation/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admin = nil, context = nil) ⇒ Evaluator

Returns a new instance of Evaluator.



24
25
26
27
# File 'lib/trestle/navigation/block.rb', line 24

def initialize(admin=nil, context=nil)
  @admin, @context = admin, context
  @items = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Trestle::EvaluationContext

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



22
23
24
# File 'lib/trestle/navigation/block.rb', line 22

def items
  @items
end

Instance Method Details

#group(name, **options) ⇒ Object



42
43
44
45
46
47
# File 'lib/trestle/navigation/block.rb', line 42

def group(name, **options)
  @current_group = Group.new(name, **options)
  yield
ensure
  @current_group = nil
end

#item(name, path = nil, **options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trestle/navigation/block.rb', line 29

def item(name, path=nil, **options)
  if options[:group]
    group = Group.new(options[:group])
  elsif @current_group
    group = @current_group
  end

  options.merge!(group: group) if group
  options.merge!(admin: @admin) if @admin

  items << Item.new(name, path, **options)
end