Last active
October 19, 2016 07:31
-
-
Save konalegi/7213739ebe160ee16e640f899866fbfd to your computer and use it in GitHub Desktop.
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
op = ::Admin::Client::Create.(params) | |
render_client(op.profile) |
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 Admin::IncomingContact::Create < BaseOperation | |
attr_reader :client, :car, :case | |
CarContract = Class.new(Admin::Car::Create.contract) do | |
property :client_id, readable: false | |
validation :validate_client, inherit: true do | |
optional(:client_id).maybe(:int?) | |
end | |
end | |
contract do | |
property :client, form: Admin::Client::Create.contract | |
property :car, form: CarContract | |
property :case, form: Admin::Case::Create.contract | |
validation do | |
required(:client).filled | |
required(:car).filled | |
required(:case).filled | |
end | |
end | |
def setup_model!(params = {}) | |
@client = UserFabric.build_client | |
@car = ::Car.new(client: @client) | |
@case = ::Case.new(car: @car) | |
self.model = OpenStruct.new(car: @car, case: @case, client: { user: @client.user, profile: @client }) | |
end | |
def process_without_exception(params) | |
validate(params) | |
contract.save | |
end | |
end | |
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 Admin::Client::Create < BaseOperation | |
attr_reader :profile | |
contract do | |
include Reform::Form::Composition | |
properties :name, :surname, :zc_comment, on: :profile do | |
validation do | |
required(:name).filled(:str?) | |
required(:surname).filled(:str?) | |
optional(:zc_comment).maybe(:str?) | |
end | |
end | |
properties :phone, :email, on: :user do | |
required(:phone).filled(:str?) | |
optional(:email).maybe(:str?) | |
end | |
end | |
def process_without_exception(params) | |
@profile = Profile::Client.new | |
@profile.user = User.new | |
validate(params, user: @profile.user, profile: @profile) | |
contract.save | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment