Sha256: 6f21662bd8d7cfc6cd87101c1afb9db47ef5d7bb594a30465a1938648138becf

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

module GroupedScope
  module Arish
    module Associations
      module Builder
        class GroupedCollectionAssociation < GroupedAssociation
          
          private
          
          def find_ungrouped_reflection
            reflection = model.reflections[ungrouped_name]
            if reflection.blank? || [:has_many, :has_and_belongs_to_many].exclude?(reflection.macro)
              msg = "Cannot create a group scope for #{ungrouped_name.inspect}. Either the reflection is blank or not supported. " + 
                    "Make sure to call grouped_scope after the association you are trying to extend has been defined."
              raise ArgumentError, msg
            end
            reflection
          end
          
          def copy_ungrouped_reflection_options
            ungrouped_reflection.options.dup.tap do |options|
              options[:class_name] = ungrouped_reflection.class_name
              if ungrouped_reflection.source_reflection && options[:source].blank?  
                options[:source] = ungrouped_reflection.source_reflection.name 
              end
            end
          end
          
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grouped_scope-3.2.1 lib/grouped_scope/arish/associations/builder/grouped_collection_association.rb
grouped_scope-3.2.0 lib/grouped_scope/arish/associations/builder/grouped_collection_association.rb
grouped_scope-3.1.2 lib/grouped_scope/arish/associations/builder/grouped_collection_association.rb
grouped_scope-3.1.1 lib/grouped_scope/arish/associations/builder/grouped_collection_association.rb
grouped_scope-3.1.0 lib/grouped_scope/arish/associations/builder/grouped_collection_association.rb