Skip to content

Instantly share code, notes, and snippets.

@timoschilling
Forked from stoffie/operation.rb
Last active November 7, 2015 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timoschilling/2422fa17a3b085872372 to your computer and use it in GitHub Desktop.
Save timoschilling/2422fa17a3b085872372 to your computer and use it in GitHub Desktop.
can be deleted on next cleanup
class Create < Trailblazer::Operation
include Model
model Workflow
contract do
property :name
property :description
collection :steps, populate_if_empty: Step do
property :form, populate_if_empty: lambda { |params, *| Form.find(params[:workflow][:steps][:form][:id]) }
#validates :form, presence: true
property :user, populate_if_empty: lambda { |params, *| User.find(params[:workflow][:steps][:user][:id]) }
#validates :user, presence: true
end
validates :name, presence: true
validates :steps, presence: true, length: {minimum: 1}
end
def process(params)
validate(params[:workflow]) do |workflow|
workflow.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment