lib/authz/scopables/base.rb
def associated_scoping_instances_ids(instance_to_check)
        scoped_class = instance_to_check.class
        # When the instance is an instances of the Scoping Class
        # (e.g when we are checking the associated cities of a city)
        return [instance_to_check.id] if scoped_class == scoping_class

        assoc_method = scoped_class.send(association_method_name)
        instance_scope = instance_to_check.send(assoc_method)
        # instance_scope = report.city  => a city instance / nil
        # instance_scope = announcement.cities => AR Relation of Cities / (may be empty)

        if instance_scope.class == scoping_class
          # When the instance is associated with ONE instance of the scoping class
          # (e.g report is associated with one city)
          instance_scope_ids = [instance_scope.id]

        elsif instance_scope.nil?
          # When the instance is associated with ONE instance of scoping class
          # but the association is empty (e.g. a record with no city)
          instance_scope_ids = []

        elsif instance_scope.respond_to? 'pluck'
          # When the instance is associated with MANY instances of the scoping
          # class. Even if the association is empty
          # (e.g announcement is available in many cities)
          instance_scope_ids = instance_scope.pluck(:id)

        else
          raise MisconfiguredAssociation,
                scoped_class: scoped_class,
                scopable: self,
                association_method: assoc_method
        end
        instance_scope_ids
      end
# Receives an instance of any class that is scopable
# by this scopable and returns an array of ids of
# the associated scoping instances.
#
# For example:
# 1. Receives a report and returns an array with the
# the id of the city associated with the report [32]
# or [] if not associated
# 2. Receives an announcement and returns an array with the
# ids of the cites in which it is available [1,2,3]
# or [] if not associated
Receives an instance of any class that is scopable
by this scopable and returns an array of ids of
the associated scoping instances.

For example:
1. Receives a report and returns an array with the
the id of the city associated with the report [32]
or [] if not associated
2. Receives an announcement and returns an array with the
ids of the cites in which it is available [1,2,3]
or [] if not associated
Receives an instance of any class that is scopable by this scopable and returns an array of ids of the associated scoping instances . For example : 1 . Receives a report and returns an array with the the id of the city associated with the report [ 32 ] or [] if not associated 2 . Receives an announcement and returns an array with the ids of the cites in which it is available [ 1 2 3 ] or [] if not associated
def associated_scoping_instances_ids(instance_to_check)
        scoped_class = instance_to_check.class
        return [instance_to_check.id] if scoped_class == scoping_class
        assoc_method = scoped_class.send(association_method_name)
        instance_scope = instance_to_check.send(assoc_method)
        if instance_scope.class == scoping_class
          instance_scope_ids = [instance_scope.id]
        elsif instance_scope.nil?
          instance_scope_ids = []
        elsif instance_scope.respond_to? 'pluck'
          instance_scope_ids = instance_scope.pluck(:id)
        else
          raise MisconfiguredAssociation,
                scoped_class: scoped_class,
                scopable: self,
                association_method: assoc_method
        end
        instance_scope_ids
      end
def associated_scoping_instances_ids ( instance_to_check ) scoped_class = instance_to_check . class return [ instance_to_check . id ] if scoped_class == scoping_class assoc_method = scoped_class . send ( association_method_name ) instance_scope = instance_to_check . send ( assoc_method ) if instance_scope . class == scoping_class instance_scope_ids = [ instance_scope . id ] elsif instance_scope . nil? instance_scope_ids = [ ] elsif instance_scope . respond_to? 'pluck' instance_scope_ids = instance_scope . pluck ( :id ) else raise MisconfiguredAssociation , scoped_class : scoped_class , scopable : self , association_method : assoc_method end instance_scope_ids end
Receives an instance of any class that is scopable
by this scopable and returns an array of ids of
the associated scoping instances.
Receives an instance of any class that is scopable by this scopable and returns an array of ids of the associated scoping instances .
# When the instance is an instances of the Scoping Class # (e.g when we are checking the associated cities of a city) # instance_scope = report.city  => a city instance / nil # instance_scope = announcement.cities => AR Relation of Cities / (may be empty) # When the instance is associated with ONE instance of the scoping class # (e.g report is associated with one city) # When the instance is associated with ONE instance of scoping class # but the association is empty (e.g. a record with no city) # When the instance is associated with MANY instances of the scoping # class. Even if the association is empty # (e.g announcement is available in many cities)
instance_to_check