Created
December 6, 2016 13:29
-
-
Save eqbal/cd710d54a0f9842d69764a6be4c9dc67 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Entry < ActiveRecord::Base | |
validates :status_weather, inclusion: { | |
in: EntryStatus::OPTIONS[:weather] | |
} | |
validates :status_landform, inclusion: { | |
in: EntryStatus::OPTIONS[:landform] | |
} | |
.... | |
def status | |
@status ||= EntryStatus.new(status_weather, status_landform) | |
end | |
def status=(status) | |
self[:status_weather] = status.weather | |
self[:status_landform] = status.landform | |
@status = status | |
end | |
.... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't a more robust implementation for status=(status) be:
In that way, you decouple from the implementation of the value passed in, which may be a mutable struct instead of your immutable value object. Would you agree?