Class: ActiveRecord::Collection
- Inherits:
-
Object
- Object
- ActiveRecord::Collection
- Includes:
- ActiveRecord::Collections::Batching, ActiveRecord::Collections::Delegation, ActiveRecord::Collections::Pagination, ActiveRecord::Collections::Records, ActiveRecord::Collections::Relation, ActiveRecord::Collections::Serialization
- Defined in:
- lib/active_record/collection.rb
Class Attribute Summary collapse
-
.collections ⇒ Object
readonly
Returns the value of attribute collections.
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::Pagination
#current_page, #default_per_page, #first_page?, included, #last_page?, #next_page, #next_page?, #out_of_range?, #page, #page!, #paginate!, #per, #per!, #per_page, #prev_page, #prev_page?, #total_pages
Methods included from ActiveRecord::Collections::Serialization
#as_json, 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, #batch!, #batch_by_default?, #batch_map, #batch_size, #batchify!, #batching_threshold, #current_batch, #default_batch_size, #each_batch, #first_batch, #first_batch!, #flat_batch_map, included, #is_batch!, #is_batch?, #is_batched?, #last_batch, #last_batch!, #next_batch, #next_batch!, #next_batch?, #per_batch, #per_batch!, #prev_batch, #prev_batch!, #prev_batch?, #should_batch?, #to_batches, #total_batches
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
Methods included from ActiveRecord::Collections::Relation
#all, #distinct, #distinct!, #group, #group!, included, #includes, #includes!, #joins, #joins!, #limit, #limit!, #load, #not, #not!, #offset, #offset!, #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
Class Attribute Details
.collections ⇒ Object (readonly)
Returns the value of attribute collections.
12 13 14 |
# File 'lib/active_record/collection.rb', line 12 def collections @collections end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/active_record/collection.rb', line 9 def @options end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
9 10 11 |
# File 'lib/active_record/collection.rb', line 9 def relation @relation end |
Class Method Details
.collectable(klass = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_record/collection.rb', line 17 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 |
.inherited(subclass) ⇒ Object
13 14 15 |
# File 'lib/active_record/collection.rb', line 13 def inherited(subclass) (@collections ||= []) << subclass end |
.model ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_record/collection.rb', line 35 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
38 39 40 |
# File 'lib/active_record/collection.rb', line 38 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
45 46 47 48 49 50 51 |
# File 'lib/active_record/collection.rb', line 45 def inspect relation_backup = relation.dup @records = @relation = relation.none inspected = super @records = @relation = relation_backup inspected end |