lib/action_policy/policy/authorization.rb in action_policy-0.3.2 vs lib/action_policy/policy/authorization.rb in action_policy-0.3.3
- old
+ new
@@ -47,14 +47,18 @@
super(*args)
@authorization_context = {}
self.class.authorization_targets.each do |id, opts|
- raise AuthorizationContextMissing, id unless params.key?(id)
+ if opts[:optional] == true
+ val = params.fetch(id, nil)
+ else
+ raise AuthorizationContextMissing, id unless params.key?(id)
- val = params.fetch(id)
+ val = params.fetch(id)
- raise AuthorizationContextMissing, id if val.nil? && opts[:allow_nil] != true
+ raise AuthorizationContextMissing, id if val.nil? && opts[:allow_nil] != true
+ end
authorization_context[id] = instance_variable_set("@#{id}", val)
end
authorization_context.freeze