Module: BreakDance::PolicyAdditions
- Defined in:
- lib/break_dance/policy_additions.rb
Instance Method Summary collapse
-
#exclude_select_values(model, select_values) ⇒ Object
ToDo: Check & fix if we need to redefine also object.attributes or any other method to return us all attributes skipping direct attribute method call I.e.
- #resource(key, resource) ⇒ Object
- #scope(model) ⇒ Object
Instance Method Details
#exclude_select_values(model, select_values) ⇒ Object
ToDo: Check & fix if we need to redefine also object.attributes or any other method to return us all attributes skipping direct attribute method call
I.e. we now will receive 'nil' if a "column" is excluded, but we may access it via Object.find(x).attributes[:excluded_attribute]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/break_dance/policy_additions.rb', line 19 def exclude_select_values(model, select_values) RequestLocals.store[:break_dance_policy] ||= BreakDance::Policy.new RequestLocals.store[:break_dance_policy].excluded_select_values[model.name] = select_values select_values.each do |sv| model.redefine_method sv do if RequestLocals.store[:break_dance_policy]&.excluded_select_values[model.name]&.include? sv nil else super() end end end end |
#resource(key, resource) ⇒ Object
11 12 13 14 15 |
# File 'lib/break_dance/policy_additions.rb', line 11 def resource(key, resource) RequestLocals.store[:break_dance_policy] ||= BreakDance::Policy.new RequestLocals.store[:break_dance_policy].resources[key] = resource end |
#scope(model) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/break_dance/policy_additions.rb', line 3 def scope(model) RequestLocals.store[:break_dance_policy] ||= BreakDance::Policy.new model_scope = RequestLocals.store[:break_dance_policy].scopes[model.name] RequestLocals.store[:break_dance_policy].scopes[model.name] = model_scope.nil? ? yield(model.unscoped) : model_scope.merge(yield(model.unscoped)) end |