* 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
32 lines
719 B
Ruby
32 lines
719 B
Ruby
# This service removes a profile field and ensures that the corresponding store
|
|
# accessor also gets removed immediately.
|
|
module ProfileFields
|
|
class Remove
|
|
def self.call(id)
|
|
new(id).call
|
|
end
|
|
|
|
attr_reader :profile_field, :error_message
|
|
|
|
def initialize(id)
|
|
@id = id
|
|
@success = false
|
|
end
|
|
|
|
def call
|
|
@profile_field = ProfileField.find(@id)
|
|
if @profile_field.destroy
|
|
accessor = profile_field.attribute_name.to_s
|
|
Profile.undef_method(accessor) if accessor.in?(Profile.attributes)
|
|
@success = true
|
|
else
|
|
@error_message = @profile_field.errors_as_sentence
|
|
end
|
|
self
|
|
end
|
|
|
|
def success?
|
|
@success
|
|
end
|
|
end
|
|
end
|