Snapi
Section 8
Affirmation
Builder
Responsibility
-
Converts params into a template for creating and updating items.
include magic
class ContactCurator < BaseCurator
include Omicron.authorization(ContactAuthorizer)
def create_action
pipe(default_response, :through => [
:build, :validate, :authorize_to_write, :create,
:apply_readables, :publish_create, :decorate
])
end
def update_action
pipe(default_response, :through => [
:find, :build, :remove_shared_access, :validate,
:authorize_to_update, :update, :update_user, :apply_readables,
:publish_update, :decorate
])
end
end
We use the include magic to
inject build into the curator.
Concepts
-
build
-
create_template
-
update_template
-
model
-
deprecated_attributes
class ContactBuilder < MasterBuilder
private
def deprecated_attributes
{
:hide_address => :is_address_hidden
}
end
def model
Contact
end
def create_template
process_template(:allowed => [
:label, :position, :address_street1, :address_street2,
:address_city, :address_state, :address_zip, :address_country,
:first_name, :last_name, :is_address_hidden, :allow_shared_access,
:member_id
])
end
def update_template
process_template(:allowed => [
:label, :position, :address_street1, :address_street2,
:address_city, :address_state, :address_zip, :address_country,
:first_name, :last_name, :is_address_hidden, :allow_shared_access
])
end
end
build
Build takes the params and combines it with the template to either create a new item or update an existing item in the collection.
Title Text
- sanitize_template
- Bullet Two
- Bullet Three
Builder
Responsibility
-
Converts params into an item
Thank you!
Snapi Section 08 Affirmation
By Dustin McCraw
Snapi Section 08 Affirmation
- 675