Created
February 16, 2015 19:32
-
-
Save odigity/045bd5d6fe674f1e6074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Membership < ActiveRecord::Base | |
value_object :period, Period # using: https://github.com/kasperbn/value_object_ar | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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