Module: OpenStax::Utilities::DelegateAccessControl
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/openstax/utilities/delegate_access_control.rb
Instance Method Summary collapse
-
#delegate_access_control(options = {}) ⇒ Object
Adds code to an ActiveRecord object to delegate its access control methods to another object.
-
#delegate_access_control_to(relation, options = {}) ⇒ Object
Convenience method for delegate_access_control.
Instance Method Details
#delegate_access_control(options = {}) ⇒ Object
Adds code to an ActiveRecord object to delegate its access control methods to another object.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/openstax/utilities/delegate_access_control.rb', line 20 def delegate_access_control(={}) configuration = {include_sort: false} configuration.update() if .is_a?(Hash) raise IllegalArgument, "A :to option must be provided" if configuration[:to].blank? configuration[:to] = configuration[:to].to_s class_eval <<-EOV delegate :can_be_read_by?, :can_be_updated_by?, to: :#{configuration[:to]} # Delegating creation and destroying of this contained object means you can # update the containing object alias_method :can_be_created_by?, :can_be_updated_by? alias_method :can_be_destroyed_by?, :can_be_updated_by? if #{configuration[:include_sort]} alias_method :can_be_sorted_by?, :can_be_updated_by? end EOV end |
#delegate_access_control_to(relation, options = {}) ⇒ Object
Convenience method for delegate_access_control
47 48 49 |
# File 'lib/openstax/utilities/delegate_access_control.rb', line 47 def delegate_access_control_to(relation, = {}) delegate_access_control .merge(to: relation) end |