Class: ActiveRecord::Precount::CountLoaderBuilder
- Inherits:
-
Object
- Object
- ActiveRecord::Precount::CountLoaderBuilder
- Defined in:
- lib/active_record/precount/count_loader_builder.rb
Instance Method Summary collapse
- #build_from_has_many(name, scope, options) ⇒ Object
- #build_from_query_methods(*args) ⇒ Object
-
#initialize(model) ⇒ CountLoaderBuilder
constructor
A new instance of CountLoaderBuilder.
Constructor Details
#initialize(model) ⇒ CountLoaderBuilder
Returns a new instance of CountLoaderBuilder.
6 7 8 |
# File 'lib/active_record/precount/count_loader_builder.rb', line 6 def initialize(model) @model = model end |
Instance Method Details
#build_from_has_many(name, scope, options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/active_record/precount/count_loader_builder.rb', line 10 def build_from_has_many(name, scope, ) name_with_count = if [:count_loader].is_a?(Symbol) [:count_loader] else :"#{name}_count" end add_reflection(name_with_count, scope, ) end |
#build_from_query_methods(*args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record/precount/count_loader_builder.rb', line 21 def build_from_query_methods(*args) args.each do |arg| next if ReflectionChecker.has_reflection?(@model, counter_name = :"#{arg}_count") unless ReflectionChecker.has_reflection?(@model, arg) raise ArgumentError, "Association named '#{arg}' was not found on #{@model.name}." end original_reflection = @model.reflections[arg.to_s] add_reflection(counter_name, original_reflection.scope, original_reflection.) end end |