No commit activity in last 3 years
No release in over 3 years
Keep your code clean with simple interactions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
 Project Readme

Code Climate

Codeship Status for boza/interaction

Interaction

Interactions are meant to keep controllers and models or any other business logic slim (YAY). Keep intention of class clear when using interactions, for example: To create a user, a class should be name Users::Create.

If you are using this in a Rails application you might want to use

gem 'simple_interaction-rails, github: "boza/simple_interaction-rails"'

this comes with a generator so you don't have to create individual files :)

Installation

Add this line to your application's Gemfile:

gem 'simple_interaction'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_interaction

Usage

class Klass
  include SimpleInteraction

  fail_with 'ErrorClass'
  requires :param1, :param2     

  private
  
  def run
    method
  rescue => e
    @error = e.message
  end

  def method
    param1 / param2
  end

end

interaction = Klass.run(param1: 2, param2: 1)
interaction.success? #=> true
interaction.error #=> nil
interaction.result #=> 2

Klass.run!(param1: 1, param2: 0) #=> raises Klass::ErrorClass
Klass.run!(param1: 1, param2: 2) #=> 2

Contributing

  1. Fork it ( https://github.com/[my-github-username]/interaction/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request