Class: Trestle::Scopes::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/scopes/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefinition

Returns a new instance of Definition.



6
7
8
9
# File 'lib/trestle/scopes/definition.rb', line 6

def initialize
  @blocks = []
  @options = {}
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



4
5
6
# File 'lib/trestle/scopes/definition.rb', line 4

def blocks
  @blocks
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/trestle/scopes/definition.rb', line 4

def options
  @options
end

Instance Method Details

#append(**defaults, &block) ⇒ Object



11
12
13
# File 'lib/trestle/scopes/definition.rb', line 11

def append(**defaults, &block)
  @blocks << Block.new(**defaults, &block)
end

#apply_options!(options) ⇒ Object



15
16
17
# File 'lib/trestle/scopes/definition.rb', line 15

def apply_options!(options)
  @options.merge!(options)
end

#evaluate(context) ⇒ Object

Evaluates each of the scope blocks within the given admin context and returns a hash of Scope objects keyed by the scope name.



21
22
23
# File 'lib/trestle/scopes/definition.rb', line 21

def evaluate(context)
  @blocks.map { |block| block.scopes(context) }.flatten.index_by(&:name)
end