https://github.com/garno/stairway
Easy step by step processing of your business logic.
https://github.com/garno/stairway
Last synced: about 1 year ago
JSON representation
Easy step by step processing of your business logic.
- Host: GitHub
- URL: https://github.com/garno/stairway
- Owner: garno
- License: mit
- Created: 2013-09-29T02:40:57.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-10-16T15:04:58.000Z (over 12 years ago)
- Last Synced: 2025-04-18T03:24:30.850Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 143 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stairway
Easy step by step processing of your business logic.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'stairway'
```
## Usage
First, create a new *initializer* to define the different steps of your Stairway:
```ruby
# config/initializers/stairways.rb
import = Stairway::Stairs.new(:import)
import.steps = {
download: ImportSchedule::Download.new,
unzip: ImportSchedule::Unzip.new,
convert_sql: ImportSchedule::ConvertToSQL.new,
import: ImportSchedule::Import.new
clean: ImportSchedule::Cleanup.new
}
Stairway.register(import)
```
Now, you can run the logic from anywhere in your application using:
```ruby
Stairway.mount(:import).run
```
## Define your steps
In the above section, you can see a `ImportSchedule::Download` class being intanciated. All your step should at least, respond to the `run` method. This method will be automatically called.
```ruby
module ImportSchedule
class Download < Stairway::Step
def run
# do stuff here…
context[:file_path] = '/tmp/boom.zip'
# `context` is available in all the steps
# and can be modified.
end
emd
end
```
## Break the flow
At any time, if you want to stop the processing for whatever reason, you can do this:
```ruby
module ImportSchedule
class Download < Stairway::Step
def run
begin
# download your content…
rescue DownloadError
Stairway.stop
end
end
end
end
```
## Run a single step
Sometime, I guess, you'll want to run a single step.
```ruby
Stairway.mount(:import).run_step(:download, context, options)
```
## License
Stairway is © 2013-2014 [Samuel Garneau](http://twitter.com/garno) and may be freely distributed under the [MIT license](https://github.com/garno/stairway/blob/master/LICENSE). See the `LICENSE` file.