Project

servizio

0.0
No commit activity in last 3 years
No release in over 3 years
Yet another service object support library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0
< 4.0.0, >= 3.0.0
>= 0.8.0

Runtime

>= 4.0.0
 Project Readme

Servizio

Build Status Test Coverage Code Climate Dependency Status

Servizio is a gem to support you creating service objects. It was created after I read a blog post about service objects from Philippe Creux. Realy great post, check it out.

I liked the ideas presented there, so I began to use them. Quickly I realised, that combining the basic concepts presented in this post with something like ActiveModel would be awesome. So there was Servizio.

TL;DR

Servizio is a class you can derive your service classes from. It includes ActiveModel::Model and ActiveModel::Validations and wraps the call method of the derived class by prepending some code to the derived class' singleton class. The main purpose is to provide some conventions for and to ease the creation of service classes.

class MyService < Servizio::Service
  attr_accessor :summands

  validates_presence_of :summands

  def call
    summands.reduce(:+)
  end
end

# create an instance of a service (a.k.a. an operation)
operation = MyService.new(operands: [1,2,3])

# call the operation and get it's result
operation.call!.result # => 6

Additional readings

Contributing

  1. Fork it ( https://github.com/msievers/servizio/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