Class: OSC::Reservations::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/osc/reservations/query.rb

Overview

Factory for creating reservation objects that detail the current user’s reservations on the given batch server.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, batch) ⇒ Query



41
42
43
44
# File 'lib/osc/reservations/query.rb', line 41

def initialize(adapter, batch)
  @adapter = adapter
  @batch = batch
end

Class Method Details

.method_missing(method_name, *arguments, &block) ⇒ Object

See if the method call exists as a key in batch config yaml file. Examples:

Query.glenn()
Query.oakley()


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/osc/reservations/query.rb', line 16

def self.method_missing(method_name, *arguments, &block)
  context = Reservations.batch_config[method_name.to_s]
  if context
    adapter_type  = context['adapter']['type']
    batch_server  = context['batch'].delete('server')
    batch_context = context['batch']
    a = Object.const_get(adapter_type).new
    b = Batch.new(batch_server, batch_context)
    new(a, b)
  else
    super
  end
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Checks if the method responds to an instance method, or is able to proxy it to the batch config yaml file.



35
36
37
# File 'lib/osc/reservations/query.rb', line 35

def self.respond_to_missing?(method_name, include_private = false)
  Reservations.batch_config.include?(method_name.to_s) || super
end

Instance Method Details

#reservation(id) ⇒ Reservation?

Query the reservation information for a given reservation id.



49
50
51
# File 'lib/osc/reservations/query.rb', line 49

def reservation(id)
  @adapter.query_reservation(@batch, id)
end

#reservationsArray<Reservation>

Query for all the reservations.



55
56
57
# File 'lib/osc/reservations/query.rb', line 55

def reservations
  @adapter.query_reservations(@batch)
end