lib/goldiloader/association_info.rb in goldiloader-1.0.1 vs lib/goldiloader/association_info.rb in goldiloader-2.0.0

- old
+ new

@@ -5,121 +5,36 @@ def initialize(association) @association = association end - def finder_sql? - Goldiloader::Compatibility.association_finder_sql_enabled? && - association_options[:finder_sql].present? + delegate :association_scope, :reflection, to: :@association + + def offset? + association_scope && association_scope.offset_value.present? end - if ActiveRecord::VERSION::MAJOR >= 4 - delegate :association_scope, :reflection, to: :@association + def limit? + association_scope && association_scope.limit_value.present? + end - def read_only? - association_scope && association_scope.readonly_value.present? - end + def auto_include? + association_scope.nil? || association_scope.auto_include_value + end - def offset? - association_scope && association_scope.offset_value.present? + def from? + if ActiveRecord::VERSION::MAJOR >= 5 + association_scope && association_scope.from_clause.present? + else + association_scope && association_scope.from_value.present? end + end - def limit? - association_scope && association_scope.limit_value.present? - end - - def from? - if ActiveRecord::VERSION::MAJOR >= 5 - association_scope && association_scope.from_clause.present? - else - association_scope && association_scope.from_value.present? - end - end - - def group? - association_scope && association_scope.group_values.present? - end - - def joins? - return false unless association_scope - - num_joins = association_scope.joins_values.size - if ActiveRecord::VERSION::MAJOR >= 5 - num_joins += association_scope.left_joins_values.size + association_scope.left_outer_joins.size - end - # Yuck - Through associations will always have a join for *each* 'through' table - num_joins - num_through_joins > 0 - end - - def uniq? - association_scope && association_scope.uniq_value - end - - def instance_dependent? - reflection.scope.present? && reflection.scope.arity > 0 - end - - def unscope? - Goldiloader::Compatibility.unscope_query_method_enabled? && - association_scope && - association_scope.unscope_values.present? - end - - private - - def num_through_joins - association = @association - count = 0 - while association.is_a?(ActiveRecord::Associations::ThroughAssociation) - count += 1 - association = association.owner.association(association.through_reflection.name) - end - count - end - else - def read_only? - association_options[:readonly].present? - end - - def offset? - association_options[:offset].present? - end - - def limit? - association_options[:limit].present? - end - - def from? - false - end - - def group? - association_options[:group].present? - end - - def joins? - # Rails 3 didn't support joins for associations - false - end - - def uniq? - association_options[:uniq] - end - - def instance_dependent? - # Rails 3 didn't support this - false - end - - def unscope? - # Rails 3 didn't support this - false - end + def group? + association_scope && association_scope.group_values.present? end - private - - def association_options - @association.options + def instance_dependent? + reflection.scope.present? && reflection.scope.arity > 0 end end end