Skip to content

Instantly share code, notes, and snippets.

@odigity
Created February 16, 2015 19:32
Show Gist options
  • Save odigity/045bd5d6fe674f1e6074 to your computer and use it in GitHub Desktop.
Save odigity/045bd5d6fe674f1e6074 to your computer and use it in GitHub Desktop.
class Membership < ActiveRecord::Base
value_object :period, Period # using: https://github.com/kasperbn/value_object_ar
end
class Period
attr_accessor :value
def initialize(value)
@value = value
end
def end_date
(value.last == Float::INFINITY) ? value.last : (value.last - 1.day) # PostgreSQL daterange values get loaded by Rails with an exclusive upper bound
end
def start_date
value.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment