Class: Lafcadio::Query::Max

Inherits:
Lafcadio::Query show all
Defined in:
lib/lafcadio/query.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Lafcadio::Query

#condition, #domain_class, #include, #limit, #order_by, #order_by_order

Instance Method Summary collapse

Methods inherited from Lafcadio::Query

And, Or, #and, #compound, #dobj_satisfies?, #eql?, #hash, #implies?, infer, #limit_clause, #one_pk_id?, #or, #order_and_limit_collection, #order_clause, #sql_primary_key_field, #tables, #to_sql, #where_clause

Constructor Details

#initialize(domain_class, field_name = 'pk_id') ⇒ Max

Returns a new instance of Max.



684
685
686
687
# File 'lib/lafcadio/query.rb', line 684

def initialize( domain_class, field_name = 'pk_id' )
	super( domain_class )
	@field_name = field_name
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



682
683
684
# File 'lib/lafcadio/query.rb', line 682

def field_name
  @field_name
end

Instance Method Details

#collect(coll) ⇒ Object



689
690
691
692
693
694
695
# File 'lib/lafcadio/query.rb', line 689

def collect( coll )
	max = coll.inject( nil ) { |max, d_obj|
		a_value = d_obj.send @field_name
		( max.nil? || a_value > max ) ? a_value : max
	}
	[ result_row( [max] ) ]
end

#fieldsObject



697
698
699
# File 'lib/lafcadio/query.rb', line 697

def fields
	"max(#{ @domain_class.field( @field_name ).db_field_name })"
end

#result_row(row) ⇒ Object



701
# File 'lib/lafcadio/query.rb', line 701

def result_row( row ); { :max => row.first }; end