* Add Profiles::Update service object * Refactor * Rename Profile.fields to Profile.attributes * Keep sync from user -> profile * And and update comments * Rename Profile.refresh_store_accessors! * Make forwarding getters in user dynamic * Add more explanation * Fix typo * Update service object * Fix return value * Fix specs * Travis, let's be friends again? * Remove Travis change * Add require_dependency in Profile * Refactor * More refactoring * Avoid double sync * Fix specs * Fix mapped attributes sync
31 lines
680 B
Ruby
31 lines
680 B
Ruby
# This service creates a new profile field and ensures that the correct store
|
|
# accessor gets added to profiles immediately.
|
|
module ProfileFields
|
|
class Add
|
|
def self.call(attributes)
|
|
new(attributes).call
|
|
end
|
|
|
|
attr_reader :profile_field, :error_message
|
|
|
|
def initialize(attributes)
|
|
@attributes = attributes
|
|
@success = false
|
|
end
|
|
|
|
def call
|
|
@profile_field = ProfileField.create(@attributes)
|
|
if @profile_field.persisted?
|
|
@success = true
|
|
Profile.refresh_attributes!
|
|
else
|
|
@error_message = @profile_field.errors_as_sentence
|
|
end
|
|
self
|
|
end
|
|
|
|
def success?
|
|
@success
|
|
end
|
|
end
|
|
end
|