Module: Godmin::Helpers::Application

Defined in:
lib/godmin/helpers/application.rb

Instance Method Summary collapse

Instance Method Details

#partial_override(partial, locals = {}, &block) ⇒ Object

Renders the provided partial with locals if it exists, otherwise yields the given block. The lookup context call is cached for each partial.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/godmin/helpers/application.rb', line 7

def partial_override(partial, locals = {}, &block)
  @_partial_override ||= {}

  unless @_partial_override.key?(partial)
    @_partial_override[partial] = lookup_context.exists?(partial, nil, true)
  end

  if @_partial_override[partial]
    render partial: partial, locals: locals
  else
    capture(&block)
  end
end

#policy(resource) ⇒ Object

Wraps the policy helper so that it is always accessible, even when authorization is not enabled. When that is the case, it returns a policy that always returns true.



24
25
26
27
28
29
30
# File 'lib/godmin/helpers/application.rb', line 24

def policy(resource)
  if authorization_enabled?
    super(resource)
  else
    Authorization::Policy.new(nil, nil, default: true)
  end
end