Skip to content

Instantly share code, notes, and snippets.

View rafaels88's full-sized avatar
🔮
coming up with something

Rafael Soares dos Santos rafaels88

🔮
coming up with something
View GitHub Profile
@rafaels88
rafaels88 / quiqup.opus_assign_convention.ex
Last active September 20, 2018 21:23
Quiqup - Opus assign convention
defmodule Quiqup.DispatchOrderStagePipeline do
use Opus.Pipeline
step :assign_availability
step :persist, if: :available?
step :send_alert, if: :persisted?
def assign_availability(pipeline) do
put_in(pipeline, [:availability], :unavailable)
end
@rafaels88
rafaels88 / quiqup.opus_step.ex
Created September 11, 2018 10:30
Quiqup - Opus Step
defmodule Quiqup.DispatchOrderStagePipeline do
use Opus.Pipeline
step :assign_courier
step :next_stage
def assign_courier(%{order: order} = pipeline) do
put_in(pipeline, [:courier], order.courier)
end
@rafaels88
rafaels88 / quiqup.dispatch_order_stage_pipeline.ex
Created September 11, 2018 10:28
Quiqup - Opus, the stages
defmodule Quiqup.DispatchOrderStagePipeline do
use Opus.Pipeline
check :validate_order
step :persist_stage
def validate_order(%{order: order} = pipeline) do
# validation code returns true or false
end
@rafaels88
rafaels88 / quiqup.dispatch_order_stage_pipeline.ex
Created September 11, 2018 10:27
Quiqup - Opus Quiqup.DispatchOrderStagePipeline
defmodule Quiqup.DispatchOrderStagePipeline do
use Opus.Pipeline
check :validate_order
step :assign_next_stage_slug
step :assign_courier
check :courier_available?
step :persist_stage
link PushNotificationPipeline
tee :emit_event
@rafaels88
rafaels88 / quiqup.dispatch_order_stage_pipeline.ex
Created September 11, 2018 10:24
Quiqup.DispatchOrderStagePipeline
defmodule Quiqup.DispatchOrderStagePipeline do
def call(%{order_id: order_id}) do
with {:ok, %{courier: courier} = order} <- validate_order(order),
{:ok, true} <- courier_available?(courier),
{:ok, next_stage_slug} <- next_stage_slug_by(order),
{:persist_stage, {:ok, %Stage{} = stage}}
<- {:persist_stage, %{order: order} |> create_stage(next_stage_slug)},
{:push_notification, :ok}
<- {:push_notification, push_notification(%{courier: courier, stage: stage})},
{:emit_event, :ok}
@rafaels88
rafaels88 / factory_girl_helper.rb
Last active March 3, 2019 21:21
Factory Girl helper to work with Hanami Framework
# USAGE
# 1. Add 'factory_girl' in Gemfile as a dependency. But here, be careful. Factory Girl adds Active Support
# as its dependency, so it is up to you add it in :development and :test group or add it for all envs.
# For more details, read the comment from @cllns below.
# 2. Save this file in '/spec';
# 3. Load this file in 'spec_helper.rb' as the last require in the file, using:
# require_relative './factory_girl_helper'
@rafaels88
rafaels88 / sluggable.rb
Last active August 26, 2018 20:40
Hanami Sluggable (Slugify) Module
# lib/your_app/ext/sluggable.rb
module Sluggable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def sluggable(field)
@field = field