Method: Invoicing::TimeDependent::ClassMethods#valid_records_at

Defined in:
lib/invoicing/time_dependent.rb

#valid_records_at(point_in_time) ⇒ Object

Returns the list of all records which are valid at one particular point in time. If you need to consider a period of time rather than a point in time, use valid_records_during.



252
253
254
255
256
257
258
259
260
261
# File 'lib/invoicing/time_dependent.rb', line 252

def valid_records_at(point_in_time)
  info = time_dependent_class_info
  all.select do |record|
    valid_from  = info.get(record, :valid_from)
    valid_until = info.get(record, :valid_until)
    has_taken_effect = (valid_from <= point_in_time) # N.B. less than or equals
    not_yet_expired  = (valid_until == nil) || (valid_until > point_in_time)
    has_taken_effect && not_yet_expired
  end
end