Class: Trestle::Scopes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/trestle/scopes.rb,
lib/trestle/scopes/block.rb,
lib/trestle/scopes/scope.rb,
lib/trestle/scopes/definition.rb

Defined Under Namespace

Classes: Block, Definition, Scope

Instance Method Summary collapse

Constructor Details

#initialize(definition, context) ⇒ Scopes

Returns a new instance of Scopes.


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

def initialize(definition, context)
  @definition = definition
  @scopes = @definition.evaluate(context)
end

Instance Method Details

#active(params) ⇒ Object


41
42
43
# File 'lib/trestle/scopes.rb', line 41

def active(params)
  select { |s| s.active?(params) }
end

#classesObject


16
17
18
19
20
21
22
23
# File 'lib/trestle/scopes.rb', line 16

def classes
  [
    'scopes',
    ('grouped' if grouped?),
    layout_class,
    options[:class]
  ].compact
end

#each(&block) ⇒ Object


25
26
27
# File 'lib/trestle/scopes.rb', line 25

def each(&block)
  @scopes.values.each(&block)
end

#groupedObject


33
34
35
36
37
38
39
# File 'lib/trestle/scopes.rb', line 33

def grouped
  if grouped?
    group_by(&:group)
  else
    { nil => @scopes.values.flatten }
  end
end

#grouped?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/trestle/scopes.rb', line 29

def grouped?
  options[:group] != false && any?(&:group)
end