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 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?