Class: ActiveRecord::Collection
- Inherits:
-
Object
- Object
- ActiveRecord::Collection
- Includes:
- ActiveRecord::Collections::Batching, ActiveRecord::Collections::Delegation, ActiveRecord::Collections::Records, ActiveRecord::Collections::Relation, ActiveRecord::Collections::Serialization
- Defined in:
- lib/active_record/collection.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Class Method Summary collapse
Instance Method Summary collapse
- #collectable ⇒ Object (also: #model)
-
#inspect ⇒ Object
dup relation and call none so that we don’t end up inspecting it and loading it before we want it.
Methods included from ActiveRecord::Collections::Serialization
included, #to_hash, #to_json, #to_param, #to_sql
Methods included from ActiveRecord::Collections::Delegation
included, #method_missing, #on_records, #on_relation, #respond_to_missing?
Methods included from ActiveRecord::Collections::Batching
#as_batch, #as_batches, #as_next_batch, #batch_by_default?, #batching_threshold, #current_page, #default_batch_size, #each_page, #first_page, #first_page!, #flat_page_map, included, #is_batch!, #is_batch?, #last_page, #last_page!, #next_page, #next_page!, #next_page?, #page, #page!, #page_map, #paginated?, #per, #per!, #per_page, #prev_page, #prev_page!, #prev_page?, #should_batch?, #to_batches, #total_pages
Methods included from ActiveRecord::Collections::Records
#each, #each_in_batches, #flat_map, #flat_map_in_batches, #length, #map, #map_in_batches, #pluck, #record_ids, #records, #size, #to_ary, #total_count, #total_records
Methods included from ActiveRecord::Collections::Relation
#all, #distinct, #distinct!, included, #includes, #includes!, #joins, #joins!, #limit, #limit!, #load, #not, #not!, #or, #or!, #order, #order!, #references, #references!, #reset, #reset!, #select, #select!, #where, #where!
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveRecord::Collections::Delegation
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/active_record/collection.rb', line 8 def end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
8 9 10 |
# File 'lib/active_record/collection.rb', line 8 def relation @relation end |
Class Method Details
.collectable(klass = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_record/collection.rb', line 11 def collectable(klass=nil) unless klass.nil? raise ArgumentError, "The collection model must inherit from ActiveRecord::Base" unless klass.ancestors.include?(ActiveRecord::Base) @collectable = klass end if @collectable.nil? begin klass = self.name.demodulize.singularize.constantize @collectable = klass if !klass.nil? && klass.ancestors.include?(ActiveRecord::Base) rescue # singularized class doesn't exist end end raise "Unable to determine a model to use for your collection, please set one with the `collectable` class method" if @collectable.nil? # TODO implement real exceptions @collectable end |
.model ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_record/collection.rb', line 29 def collectable(klass=nil) unless klass.nil? raise ArgumentError, "The collection model must inherit from ActiveRecord::Base" unless klass.ancestors.include?(ActiveRecord::Base) @collectable = klass end if @collectable.nil? begin klass = self.name.demodulize.singularize.constantize @collectable = klass if !klass.nil? && klass.ancestors.include?(ActiveRecord::Base) rescue # singularized class doesn't exist end end raise "Unable to determine a model to use for your collection, please set one with the `collectable` class method" if @collectable.nil? # TODO implement real exceptions @collectable end |
Instance Method Details
#collectable ⇒ Object Also known as: model
32 33 34 |
# File 'lib/active_record/collection.rb', line 32 def collectable @collectable ||= self.class.collectable end |
#inspect ⇒ Object
dup relation and call none so that we don’t end up inspecting it and loading it before we want it
39 40 41 42 43 44 45 |
# File 'lib/active_record/collection.rb', line 39 def inspect relation_backup = relation.dup @records = @relation = relation.none inspected = super @records = @relation = relation_backup inspected end |