stairway 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 991f7c1a984f7ba0288ce5f67c93cc96714aeb4f
4
- data.tar.gz: 7635b04e3800dc5314a02055bdaa515ab46d4eac
3
+ metadata.gz: ee68673b1df74306c0cf9e9ad5c3b72bd8550155
4
+ data.tar.gz: 266a0032df11a160e8ef30a5186eac5b2cb40925
5
5
  SHA512:
6
- metadata.gz: 0bab126c567ecdb508b0822090285f6c5777ce2ef8ae6c571eeddc14e8661a5e3b188507ac98152df8d316c8f2dd4c1531ccddacfc25a3a182260c1c73081515
7
- data.tar.gz: 39f2697bb8b338e1d757901e03009bd3cf18f7995d62f2f185dc1425a38e606617aef05ea6b2a32e04916b0a803f7c7908a51ac0ee341480ff07b9848bc5d204
6
+ metadata.gz: 23e16e340229d6b479e00a6a039a22a3cee78f7f73747084c7bc8b6fc34f1fd9f1f2840f567aa8cdf3651f7d136d2892f53496d555939de39c1df8eadffa68f5
7
+ data.tar.gz: cd799981dd6a86941af2600586f4c976e693ec09ba538bb4d4e49d9a636807e8bf720271f15455d111a18eb11632d93de095bd20617979c18a0a1fe93cfe0ec7
@@ -0,0 +1 @@
1
+ pkg/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format=Fivemat
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stairway (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.4)
10
+ fivemat (1.2.1)
11
+ rake (10.1.0)
12
+ rspec (2.14.1)
13
+ rspec-core (~> 2.14.0)
14
+ rspec-expectations (~> 2.14.0)
15
+ rspec-mocks (~> 2.14.0)
16
+ rspec-core (2.14.4)
17
+ rspec-expectations (2.14.0)
18
+ diff-lcs (>= 1.1.3, < 2.0)
19
+ rspec-mocks (2.14.1)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.3)
26
+ fivemat (~> 1.2)
27
+ rake
28
+ rspec (~> 2.14)
29
+ stairway!
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013-2014 Samuel Garneau
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # Stairway
2
- Easy and intuitive step by step processing of your business logic.
3
-
4
- ---
2
+ Easy step by step processing of your business logic.
5
3
 
6
4
  ## Installation
7
5
 
8
6
  Add this line to your application's Gemfile:
9
7
 
10
- ```
8
+ ```ruby
11
9
  gem 'stairway'
12
10
  ```
13
11
 
@@ -15,10 +13,10 @@ gem 'stairway'
15
13
 
16
14
  First, create a new *initializer* to define the different steps of your Stairway:
17
15
 
18
- ```
16
+ ```ruby
19
17
  # config/initializers/stairways.rb
20
18
 
21
- import = Stairway.new(:import)
19
+ import = Stairway::Stairs.new(:import)
22
20
  import.steps = {
23
21
  download: ImportSchedule::Download.new,
24
22
  unzip: ImportSchedule::Unzip.new,
@@ -32,21 +30,26 @@ Stairway.register(import)
32
30
 
33
31
  Now, you can run the logic from anywhere in your application using:
34
32
 
35
- ```
36
- Stairway.mount(:import).run(options)
33
+ ```ruby
34
+ Stairway.mount(:import).run
37
35
  ```
38
36
 
39
37
  ## Define your steps
40
38
 
41
- In the above section, you can see a `DownloadContent` class being intanciated. All your step should at least, respond to the `run` method. This method will be automatically called.
39
+ 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.
42
40
 
43
- ```
44
- class DownloadContent
41
+ ```ruby
42
+ module ImportSchedule
43
+ class Download < Stairway::Step
44
+ def run
45
+ # do stuff here…
45
46
 
46
- def run(context, options)
47
- …do stuff here…
48
- end
47
+ context[:file_path] = '/tmp/boom.zip'
49
48
 
49
+ # `context` is available in all the steps
50
+ # and can be modified.
51
+ end
52
+ emd
50
53
  end
51
54
  ```
52
55
 
@@ -54,17 +57,17 @@ end
54
57
 
55
58
  At any time, if you want to stop the processing for whatever reason, you can do this:
56
59
 
57
- ```
58
- class DownloadContent
59
-
60
- def run(context, options)
61
- begin
62
- download your content…
63
- rescue DownloadError
64
- Stairway.stop
60
+ ```ruby
61
+ module ImportSchedule
62
+ class Download < Stairway::Step
63
+ def run
64
+ begin
65
+ # download your content…
66
+ rescue DownloadError
67
+ Stairway.stop
68
+ end
65
69
  end
66
70
  end
67
-
68
71
  end
69
72
  ```
70
73
 
@@ -72,6 +75,10 @@ end
72
75
 
73
76
  Sometime, I guess, you'll want to run a single step.
74
77
 
75
- ```
78
+ ```ruby
76
79
  Stairway.mount(:import).run_step(:download, context, options)
77
- ```
80
+ ```
81
+
82
+ ## License
83
+
84
+ 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.
@@ -1,5 +1,42 @@
1
+ require "stairway/stairs"
2
+ require "stairway/step"
1
3
  require "stairway/version"
2
4
 
5
+ # Exceptions
6
+ require "stairway/exceptions/stop"
7
+ require "stairway/exceptions/unregistered_stairs"
8
+ require "stairway/exceptions/invalid_stairs_object"
9
+
3
10
  module Stairway
4
- # Your code goes here...
11
+
12
+ @@stairs = {}
13
+
14
+ def self.register(*stairs)
15
+ stairs.each do |s|
16
+ if valid_stairs?(s)
17
+ @@stairs.merge! s.name.to_sym => s
18
+ else
19
+ raise InvalidStairsObject
20
+ end
21
+ end
22
+
23
+ true
24
+ end
25
+
26
+ def self.mount(stairs_name)
27
+ raise UnregisteredStairs unless @@stairs.include?(stairs_name)
28
+
29
+ @@stairs[stairs_name]
30
+ end
31
+
32
+ def self.stop
33
+ raise Stop
34
+ end
35
+
36
+ protected
37
+
38
+ def self.valid_stairs?(stairs)
39
+ stairs.respond_to?(:name)
40
+ end
41
+
5
42
  end
@@ -0,0 +1,4 @@
1
+ module Stairway
2
+ class InvalidStairsObject < StandardError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Stairway
2
+ class Stop < StandardError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Stairway
2
+ class UnregisteredStairs < StandardError
3
+ end
4
+ end
@@ -0,0 +1,52 @@
1
+ require 'observer'
2
+
3
+ module Stairway
4
+ class Stairs
5
+ include Observable
6
+
7
+ attr_accessor :name
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+
13
+ def steps
14
+ @steps
15
+ end
16
+
17
+ def steps=(steps)
18
+ @steps = steps
19
+
20
+ @steps.each do |name, klass|
21
+ add_observer(klass)
22
+ end
23
+ end
24
+
25
+ def run(context={}, options={})
26
+ notify(context, options)
27
+
28
+ @steps.each do |name, klass|
29
+ begin
30
+ klass.run
31
+ notify(klass.context, klass.options)
32
+ rescue Stairway::Stop
33
+ exit
34
+ end
35
+ end
36
+ end
37
+
38
+ def run_step(name, context={}, options={})
39
+ notify(context, options)
40
+
41
+ @steps[name].run
42
+ end
43
+
44
+ protected
45
+
46
+ def notify(context, options)
47
+ changed
48
+ notify_observers(context, options)
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ module Stairway
2
+ class Step
3
+
4
+ attr_accessor :context, :options
5
+
6
+ def initialize
7
+ @context = {}
8
+ end
9
+
10
+ def update(context, options)
11
+ @context = context
12
+ @options = options
13
+ end
14
+
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Stairway
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,7 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'rspec'
4
+ require 'stairway'
5
+
6
+ RSpec.configure do |config|
7
+ end
@@ -0,0 +1,45 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
+
3
+ class Klass; end
4
+
5
+ describe Stairway do
6
+ subject { Stairway }
7
+ let(:stairs) { Stairway::Stairs.new(:stairs) }
8
+ let(:klass) { Klass.new }
9
+
10
+ describe '#register' do
11
+ context 'register a valid Stairs class' do
12
+ it 'should return true' do
13
+ Stairway.register(stairs).should be_true
14
+ end
15
+ end
16
+
17
+ context 'register an unvalid Stairs class' do
18
+ it 'should raise an UnvalidStairsObject error' do
19
+ expect { Stairway.register(klass) }.to raise_error(Stairway::InvalidStairsObject)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#mount' do
25
+ context 'mount registered stairs' do
26
+ before { Stairway.register(stairs) }
27
+
28
+ it 'should return an intanciated Stairs class' do
29
+ Stairway.mount(:stairs).class.should eq(Stairway::Stairs)
30
+ end
31
+ end
32
+
33
+ context 'mount unregistered stairs' do
34
+ it 'should raise a UnregisteredStairs exception' do
35
+ expect { Stairway.mount(:ladder) }.to raise_error(Stairway::UnregisteredStairs)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe '#stop' do
41
+ it 'should raise a Stop exception' do
42
+ expect { Stairway.stop }.to raise_error(Stairway::Stop)
43
+ end
44
+ end
45
+ end
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'rspec', '~> 2.14'
24
+ spec.add_development_dependency 'fivemat', '~> 1.2'
23
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stairway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garneau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-29 00:00:00.000000000 Z
11
+ date: 2013-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fivemat
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
41
69
  description: Easy and intuitive step by step processing of your business logic.
42
70
  email:
43
71
  - samgarneau@gmail.com
@@ -45,12 +73,22 @@ executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
76
+ - .gitignore
77
+ - .rspec
48
78
  - Gemfile
49
- - LICENSE.txt
79
+ - Gemfile.lock
80
+ - LICENSE
50
81
  - README.md
51
82
  - Rakefile
52
83
  - lib/stairway.rb
84
+ - lib/stairway/exceptions/invalid_stairs_object.rb
85
+ - lib/stairway/exceptions/stop.rb
86
+ - lib/stairway/exceptions/unregistered_stairs.rb
87
+ - lib/stairway/stairs.rb
88
+ - lib/stairway/step.rb
53
89
  - lib/stairway/version.rb
90
+ - spec/spec_helper.rb
91
+ - spec/stairway_spec.rb
54
92
  - stairway.gemspec
55
93
  homepage: https://github.com/garno/stairway
56
94
  licenses:
@@ -76,4 +114,6 @@ rubygems_version: 2.0.0
76
114
  signing_key:
77
115
  specification_version: 4
78
116
  summary: Easy and intuitive step by step processing of your business logic.
79
- test_files: []
117
+ test_files:
118
+ - spec/spec_helper.rb
119
+ - spec/stairway_spec.rb
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Samuel Garneau
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.