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