Class: PeriodicCalculations::LazyQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/periodic_calculations/lazy_query.rb

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ LazyQuery

Returns a new instance of LazyQuery.



3
4
5
6
7
# File 'lib/periodic_calculations/lazy_query.rb', line 3

def initialize(query)
  @query = query
  @executed = false
  @result = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/periodic_calculations/lazy_query.rb', line 9

def method_missing(method_name, *args, &block)
  if method_name == :to_sql
    @query.to_sql
  else
    lazy_result.send(method_name, *args, &block)
  end
end

Instance Method Details

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/periodic_calculations/lazy_query.rb', line 17

def respond_to?(method_name, include_private = false)
  method_name == :to_sql || super || lazy_result.respond_to?(method_name)
end

#resultObject



21
22
23
# File 'lib/periodic_calculations/lazy_query.rb', line 21

def result
  lazy_result
end