Class: AhoyCaptain::LazyComparableQuery::LazyComparison

Inherits:
Object
  • Object
show all
Includes:
ComparableQueries
Defined in:
app/queries/concerns/ahoy_captain/lazy_comparable_query.rb

Defined Under Namespace

Classes: LazyComparisonResult

Instance Method Summary collapse

Methods included from ComparableQueries

#compare_range, #comparison_params, #range

Constructor Details

#initialize(query) ⇒ LazyComparison

Returns a new instance of LazyComparison.



10
11
12
13
14
# File 'app/queries/concerns/ahoy_captain/lazy_comparable_query.rb', line 10

def initialize(query)
  @query = query
  @params = @query.params.deep_dup
  @compare = @query.class.call(comparison_params)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



16
17
18
# File 'app/queries/concerns/ahoy_captain/lazy_comparable_query.rb', line 16

def method_missing(name, *args)
  perform_operations(name, *args)
end

Instance Method Details

#perform_operations(name, *args) ⇒ Object



20
21
22
23
24
25
# File 'app/queries/concerns/ahoy_captain/lazy_comparable_query.rb', line 20

def perform_operations(name, *args)
  @query = @query.public_send(name, *args)
  @compare = @compare.public_send(name, *args)

  self
end

#resultObject



27
28
29
30
31
# File 'app/queries/concerns/ahoy_captain/lazy_comparable_query.rb', line 27

def result
  return @result if @result

  @result = LazyComparisonResult.new.tap { |comparison| comparison.current =  @query; comparison.compared_to = @compare }
end