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
# lib/your_app/ext/sluggable.rb | |
module Sluggable | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def sluggable(field) | |
@field = field |
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
# 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' |
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
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} |
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
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 |
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
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 |
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
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 |
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
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 |
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
defmodule Quiqup.DispatchOrderStagePipeline do | |
# ... | |
link PersistCollectStagePipeline, if: &PersistCollectStagePipeline.call?/1 | |
link PersistPickStagePipeline, if: &PersistPickStagePipeline.call?/1 | |
link PersistPayStagePipeline, if: &PersistPayStagePipeline.call?/1 | |
# ... | |
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
defmodule Quiqup.DispatchOrderStagePipeline do | |
use Opus.Pipeline | |
import Quiqup.Notifier, only: [emit_event: 1] | |
check :valid_input?, with: &match?(%{order: _}, &1) | |
check :validate_order, error_message: :order_is_not_valid | |
step :assign_next_stage_slug, raise: true, if: :should_assign? | |
step :assign_courier, instrument?: false | |
step :persist_stage, raise: [PersistanceError] | |
step :push_notification, retry_times: 3, retry_backoff: fn -> lin_backoff(10, 2) |> cap(100) end |
OlderNewer