Class: Toqua::Scoping::ScopeApplicable

Inherits:
Object
  • Object
show all
Defined in:
lib/toqua/scoping.rb

Class Method Summary collapse

Class Method Details

.accept?(opts, context) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/toqua/scoping.rb', line 16

def self.accept?(opts, context)
  if_condition(context, opts) && action_condition(context, opts)
end

.action_condition(context, opts) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/toqua/scoping.rb', line 20

def self.action_condition(context, opts)
  if opts[:only]
    [opts[:only]].flatten.include?(context.action_name.to_sym)
  else
    true
  end
end

.evaluate(context, object) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/toqua/scoping.rb', line 38

def self.evaluate(context, object)
  if object.respond_to?(:call)
    context.instance_exec(&object)
  else
    context.send(object)
  end
end

.if_condition(context, opts) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/toqua/scoping.rb', line 28

def self.if_condition(context, opts)
  if opts[:if]
    !!evaluate(context, opts[:if])
  elsif opts[:unless]
    !evaluate(context, opts[:unless])
  else
    true
  end
end