Class: ActiveStorage::AwsRecord::Relation::Ordered
- Inherits:
-
Object
- Object
- ActiveStorage::AwsRecord::Relation::Ordered
- Includes:
- Enumerable
- Defined in:
- lib/active_storage/aws_record/relation.rb
Overview
Materialized, ordered result that still supports the collection helpers.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(records, attributes) ⇒ Ordered
constructor
A new instance of Ordered.
- #pluck(*attrs) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(records, attributes) ⇒ Ordered
Returns a new instance of Ordered.
134 135 136 137 |
# File 'lib/active_storage/aws_record/relation.rb', line 134 def initialize(records, attributes) @records = records.sort_by { |record| attributes.map { |attr| sort_value(record.public_send(attr)) } } @attributes = attributes end |
Instance Method Details
#each(&block) ⇒ Object
139 |
# File 'lib/active_storage/aws_record/relation.rb', line 139 def each(&block) = @records.each(&block) |
#pluck(*attrs) ⇒ Object
141 142 143 |
# File 'lib/active_storage/aws_record/relation.rb', line 141 def pluck(*attrs) @records.map { |r| attrs.size == 1 ? r.public_send(attrs.first) : attrs.map { |a| r.public_send(a) } } end |
#to_a ⇒ Object
140 |
# File 'lib/active_storage/aws_record/relation.rb', line 140 def to_a = @records.dup |