Sha256: 10ef6270d34869ed8e899f1b9928c3124df7e441ea06306950ed4d0d6343c8dd
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
# Opto/Task [![Build Status](https://travis-ci.org/kontena/opto-task.svg?branch=master)](https://travis-ci.org/kontena/opto-task) Uses [Opto](https://github.com/kontena/opto/) based [Opto/Model](https://github.com/kontena/opto-model/) to create [Mutations](https://github.com/cypriss/mutations) kind of runnable tasks or service objects. ## Installation Add this line to your application's Gemfile: ```ruby gem 'opto-task' ``` And then execute: $ bundle Or install it yourself as: $ gem install opto-task ## Usage You can define tasks: ```ruby require 'opto-task' class RemoveFileTask include Opto.task attribute :path, :string def validate add_error :path, :not_found, "The file isn't there" unless File.exist?(Path) end def perform begin File.unlink(path) "great success" rescue Errno::EACCES add_error :path, :no_access, "You don't have the rights" end end def after puts "Your file will be missed" end end ``` And then run them: ```ruby task = RemoveFileTask.new(path: '/tmp/foo.txt') result = task.run result.success? => true result.outcome => "great success" ``` ..unless they're not valid: ```ruby task = RemoveFileTask.new(path: '/tmp/foobar.txt') task.valid? => false result = task.run result.success? => false ``` ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/kontena/opto-task.
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
opto-task-0.1.1 | README.md |
opto-task-0.1.0 | README.md |