0.01
No commit activity in last 3 years
No release in over 3 years
Provides a convention for modelling user interactions as use case classes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
>= 0

Runtime

>= 1.0.4
 Project Readme

Interaction

Provides a convention for modelling user interactions as use case classes. A use case class represents and is named after something a user does with your application SignUp, RequestResetPasswordEmail etc.

Attributes are whitelisted and coerced into an expected type using Virtus. An attribute will either be the specified type or nil.

Take a look at the code itself for full details of the API provided.

A simple example

class SignUp
  include Interaction
  include ActiveModel::Validations
  include Interaction::ValidationHelpers

  # Virtus
  attribute :email, String
  attribute :password, String

  # ActiveModel validations
  validates :email, :password, presence: true

  attr_reader :user

  def perform
    validate!
    create_user
    deliver_welcome_email
  end

  private

  def create_user
    @user = User.create(attributes)
    failure! unless @user.persisted?
  end

  def deliver_welcome_email
    # ...
  end
end

sign_up = SignUp.perform(username: 'john', password: 'j0hn')
sign_up.success?
# => true
sign_up.user
# => #<User id:...>