Class: BigRecord::ArAssociations::ClassMethods::JoinDependency::JoinBase
- Inherits:
-
Object
- Object
- BigRecord::ArAssociations::ClassMethods::JoinDependency::JoinBase
- Defined in:
- lib/big_record/ar_associations.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary
-
- (Object) active_record
readonly
Returns the value of attribute active_record.
-
- (Object) table_joins
readonly
Returns the value of attribute table_joins.
Instance Method Summary
- - (Object) aliased_prefix
- - (Object) aliased_primary_key
- - (Object) aliased_table_name
- - (Object) column_names_with_alias
- - (Object) extract_record(row)
-
- (JoinBase) initialize(active_record, joins = nil)
constructor
A new instance of JoinBase.
- - (Object) instantiate(row)
- - (Object) record_id(row)
Constructor Details
- (JoinBase) initialize(active_record, joins = nil)
A new instance of JoinBase
1389 1390 1391 1392 1393 |
# File 'lib/big_record/ar_associations.rb', line 1389 def initialize(active_record, joins = nil) @active_record = active_record @cached_record = {} @table_joins = joins end |
Instance Attribute Details
- (Object) active_record (readonly)
Returns the value of attribute active_record
1386 1387 1388 |
# File 'lib/big_record/ar_associations.rb', line 1386 def active_record @active_record end |
- (Object) table_joins (readonly)
Returns the value of attribute table_joins
1386 1387 1388 |
# File 'lib/big_record/ar_associations.rb', line 1386 def table_joins @table_joins end |
Instance Method Details
- (Object) aliased_prefix
1395 1396 1397 |
# File 'lib/big_record/ar_associations.rb', line 1395 def aliased_prefix "t0" end |
- (Object) aliased_primary_key
1399 1400 1401 |
# File 'lib/big_record/ar_associations.rb', line 1399 def aliased_primary_key "#{ aliased_prefix }_r0" end |
- (Object) aliased_table_name
1403 1404 1405 |
# File 'lib/big_record/ar_associations.rb', line 1403 def aliased_table_name active_record.table_name end |
- (Object) column_names_with_alias
1407 1408 1409 1410 1411 1412 1413 1414 1415 |
# File 'lib/big_record/ar_associations.rb', line 1407 def column_names_with_alias unless @column_names_with_alias @column_names_with_alias = [] ([primary_key] + (column_names - [primary_key])).each_with_index do |column_name, i| @column_names_with_alias << [column_name, "#{ aliased_prefix }_r#{ i }"] end end return @column_names_with_alias end |
- (Object) extract_record(row)
1417 1418 1419 |
# File 'lib/big_record/ar_associations.rb', line 1417 def extract_record(row) column_names_with_alias.inject({}){|record, (cn, an)| record[cn] = row[an]; record} end |
- (Object) instantiate(row)
1425 1426 1427 |
# File 'lib/big_record/ar_associations.rb', line 1425 def instantiate(row) @cached_record[record_id(row)] ||= active_record.instantiate(extract_record(row)) end |
- (Object) record_id(row)
1421 1422 1423 |
# File 'lib/big_record/ar_associations.rb', line 1421 def record_id(row) row[aliased_primary_key] end |