module RighterForResource::ClassMethods
Public Instance Methods
create_righter_right(right_name_prefix, options = {})
click to toggle source
# File lib/injections/righter_for_resource.rb, line 9 def create_righter_right(right_name_prefix, options = {}) options[:resource] = self unless options[:resource].present? resource = options[:resource] if options[:parent_right] if options[:parent_right].is_a? Proc parent_right = options[:parent_right].call(resource) else parent_right = options[:parent_right] end parent = RighterRight.cached_find_by_name(parent_right) if parent_right end right = RighterRight.create(name: right_name(right_name_prefix, options), resource_class: resource.righter_right_resource_class, resource_id: resource.righter_right_resource_id, hidden: false, parent: parent, human_name: resource.righter_right_human_name(right_name_prefix)) if options[:auto_associate_roles] options[:auto_associate_roles].each do |role_name| role = RighterRole.find_by_name(role_name) role.add_right(right) end end right end
destroy_righter_right(right_name_prefix, options = {})
click to toggle source
# File lib/injections/righter_for_resource.rb, line 38 def destroy_righter_right(right_name_prefix, options = {}) righter_right(right_name_prefix, options).destroy end
righter_right(right_name_prefix, options = {})
click to toggle source
# File lib/injections/righter_for_resource.rb, line 42 def righter_right(right_name_prefix, options = {}) RighterRight.cached_find_by_name(right_name(right_name_prefix, options)) end
righter_right_human_name(right_name_prefix)
click to toggle source
# File lib/injections/righter_for_resource.rb, line 54 def righter_right_human_name(right_name_prefix) "#{right_name_prefix} #{righter_right_resource_class} #{righter_right_resource_id}" end
righter_right_resource_class()
click to toggle source
# File lib/injections/righter_for_resource.rb, line 46 def righter_right_resource_class name # name of the class end
righter_right_resource_id()
click to toggle source
# File lib/injections/righter_for_resource.rb, line 50 def righter_right_resource_id nil # class resources have no explicit ID end
Private Instance Methods
right_name(right_name_prefix, options = {})
click to toggle source
# File lib/injections/righter_for_resource.rb, line 60 def right_name(right_name_prefix, options = {}) unless right_name_prefix.present? fail RighterArgumentError.new('No prefix for righter_right name provided...') end resource = options[:resource] resource ||= self resource_class = resource.righter_right_resource_class resource_id = resource.righter_right_resource_id resource_id.present? ? "#{right_name_prefix}_#{resource_class}_#{resource_id}" : "#{right_name_prefix}_#{resource_class}" end