action-plan 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +7 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/action-plan.gemspec +29 -0
- data/bin/_guard-core +16 -0
- data/bin/bundler +16 -0
- data/bin/coderay +16 -0
- data/bin/console +14 -0
- data/bin/guard +16 -0
- data/bin/htmldiff +16 -0
- data/bin/launchy +16 -0
- data/bin/ldiff +16 -0
- data/bin/listen +16 -0
- data/bin/pry +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/setup +8 -0
- data/bin/thor +16 -0
- data/config/Guardfile +19 -0
- data/lib/action/base.rb +50 -0
- data/lib/action/plan.rb +101 -0
- data/lib/action/plan/version.rb +5 -0
- data/lib/action/state.rb +50 -0
- data/lib/action/state/class_methods.rb +36 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa0d0f2855aba5c8ff65e52284a7cfc6545dbae2
|
4
|
+
data.tar.gz: c2c638d88dec6b7410f891631946acdf8630e9a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e27e4fe2fa1bbdef3ab99475d37123709d3755b499ff2ed725007596fff6e242909fe58b0895efc4e9603c09bd568bbd53144d6412c107d2129966ab45547a0
|
7
|
+
data.tar.gz: 3a3111387638adb9365893a184695eb300e5cab80787a3fa479a6ee6c3b3bc6bf0fd4542b479a524e5e25ff06a359c3e7da1b28257494cbbe8afe6eb6e191ad6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
directories %w(lib spec config)
|
2
|
+
|
3
|
+
guard_rspec_options = {
|
4
|
+
cmd: "bin/rspec",
|
5
|
+
title: "Action::State",
|
6
|
+
failed_mode: :focus,
|
7
|
+
all_after_pass: true
|
8
|
+
}
|
9
|
+
|
10
|
+
guard :rspec, guard_rspec_options do
|
11
|
+
require "guard/rspec/dsl"
|
12
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
13
|
+
rspec = dsl.rspec
|
14
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
15
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
16
|
+
watch(rspec.spec_files)
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Artem Baguinski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Action::Plan
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/action/plan`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'action-plan'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install action-plan
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/action-plan.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/action-plan.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'action/plan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "action-plan"
|
8
|
+
spec.version = Action::Plan::VERSION
|
9
|
+
spec.authors = ["Artem Baguinski"]
|
10
|
+
spec.email = ["abaguinski@depraktijkindex.nl"]
|
11
|
+
|
12
|
+
spec.summary = %q{Plan and eventually execute actions}
|
13
|
+
spec.homepage = "https://github.com/artm/action-plan"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "guard", "~> 2.14"
|
25
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
26
|
+
|
27
|
+
spec.add_dependency "activesupport", "> 4.0"
|
28
|
+
spec.add_dependency "wisper", "~> 2.0.0.rc1"
|
29
|
+
end
|
data/bin/_guard-core
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application '_guard-core' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("guard", "_guard-core")
|
data/bin/bundler
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'bundler' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("bundler", "bundler")
|
data/bin/coderay
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'coderay' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("coderay", "coderay")
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "action/plan"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/guard
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'guard' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("guard", "guard")
|
data/bin/htmldiff
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'htmldiff' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("diff-lcs", "htmldiff")
|
data/bin/launchy
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'launchy' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("launchy", "launchy")
|
data/bin/ldiff
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'ldiff' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("diff-lcs", "ldiff")
|
data/bin/listen
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'listen' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("listen", "listen")
|
data/bin/pry
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'pry' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("pry", "pry")
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
data/bin/thor
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'thor' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("thor", "thor")
|
data/config/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
directories %w(lib spec config)
|
2
|
+
|
3
|
+
guard_rspec_options = {
|
4
|
+
cmd: "bin/rspec",
|
5
|
+
title: "Action::State",
|
6
|
+
failed_mode: :focus,
|
7
|
+
all_after_pass: true
|
8
|
+
}
|
9
|
+
|
10
|
+
guard :rspec, guard_rspec_options do
|
11
|
+
require "guard/rspec/dsl"
|
12
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
13
|
+
rspec = dsl.rspec
|
14
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
15
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
16
|
+
watch(rspec.spec_files)
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/lib/action/base.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "wisper"
|
2
|
+
require "active_support/configurable"
|
3
|
+
|
4
|
+
module Action
|
5
|
+
class Base
|
6
|
+
include ActiveSupport::Configurable
|
7
|
+
include Wisper::Publisher
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield config if block_given?
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
# default implementation
|
15
|
+
# plan arg is a planning DSL
|
16
|
+
def plan plan
|
17
|
+
plan.myself if respond_to?(:run)
|
18
|
+
end
|
19
|
+
|
20
|
+
# plan arg is an Action::Plan instance
|
21
|
+
def expand_into plan:
|
22
|
+
plan PlanningDSL.new(plan: plan, action: self)
|
23
|
+
end
|
24
|
+
|
25
|
+
class PlanningDSL
|
26
|
+
def initialize plan:, action:
|
27
|
+
@plan = plan
|
28
|
+
@action = action
|
29
|
+
end
|
30
|
+
|
31
|
+
def myself
|
32
|
+
@plan.schedule_action(@action.class, @action.config)
|
33
|
+
end
|
34
|
+
|
35
|
+
def action action_class, &block
|
36
|
+
@plan.plan_action(action_class, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def todo= total
|
43
|
+
end
|
44
|
+
|
45
|
+
def done= count
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Error < RuntimeError ; end
|
50
|
+
end
|
data/lib/action/plan.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require "json"
|
2
|
+
require "wisper"
|
3
|
+
require "action/plan/version"
|
4
|
+
require "action/state"
|
5
|
+
|
6
|
+
module Action
|
7
|
+
class Plan
|
8
|
+
include Wisper::Publisher
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@schedule = []
|
12
|
+
yield DSL.new(self) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def run &block
|
16
|
+
raise NotRunnable, "#{status} plan can't be run" unless runnable?
|
17
|
+
schedule.each do |state|
|
18
|
+
next if state.status == :done
|
19
|
+
action = state.create_action
|
20
|
+
state.on(:status_changed) do |state, new_status, old_status|
|
21
|
+
broadcast :plan_state_changed, self, state, new_status, old_status
|
22
|
+
end
|
23
|
+
action.on(:progress) do |done, total|
|
24
|
+
broadcast :action_progress, self, action, done, total
|
25
|
+
end
|
26
|
+
run_action action, state, &block
|
27
|
+
break unless state.status == :done
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def action_states
|
32
|
+
schedule.dup
|
33
|
+
end
|
34
|
+
|
35
|
+
def status
|
36
|
+
Action::State.sequence_status(schedule.map(&:status))
|
37
|
+
end
|
38
|
+
|
39
|
+
RunnableStatuses = [:planned, :failed, :empty]
|
40
|
+
def runnable?
|
41
|
+
RunnableStatuses.include?(status)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_json *options
|
45
|
+
{
|
46
|
+
JSON.create_id => self.class.name,
|
47
|
+
schedule: schedule
|
48
|
+
}.to_json(*options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.json_create hash_plan
|
52
|
+
schedule = hash_plan["schedule"].map{|h| Action::State.new(h)}
|
53
|
+
Action::Plan.new.tap{ |plan|
|
54
|
+
plan.instance_variable_set(:@schedule, schedule)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def == other
|
59
|
+
self.class == other.class && schedule == other.action_states
|
60
|
+
end
|
61
|
+
|
62
|
+
class DSL
|
63
|
+
def initialize plan
|
64
|
+
@plan = plan
|
65
|
+
end
|
66
|
+
|
67
|
+
def action *args, &block
|
68
|
+
@plan.plan_action *args, &block
|
69
|
+
self
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Error < RuntimeError ; end
|
74
|
+
class NotRunnable < Error ; end
|
75
|
+
|
76
|
+
# let action plan itself
|
77
|
+
def plan_action action_class, &block
|
78
|
+
action_class.new.configure(&block).expand_into(plan: self)
|
79
|
+
end
|
80
|
+
|
81
|
+
# schedule action execution at the current point in the plan
|
82
|
+
def schedule_action action_class, config
|
83
|
+
new_state = Action::State.new(action_class: action_class, config: config)
|
84
|
+
schedule << new_state
|
85
|
+
new_state.status = :planned
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
attr_reader :schedule
|
91
|
+
|
92
|
+
def run_action action, state
|
93
|
+
state.status = :running
|
94
|
+
action.run
|
95
|
+
state.status = :done
|
96
|
+
rescue Exception => e
|
97
|
+
state.status = :failed
|
98
|
+
broadcast :action_failure, self, action, e
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/action/state.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "wisper"
|
2
|
+
require "active_support/ordered_hash"
|
3
|
+
require "active_support/core_ext/hash"
|
4
|
+
require "active_support/core_ext/string/inflections"
|
5
|
+
|
6
|
+
module Action
|
7
|
+
class State
|
8
|
+
include Wisper::Publisher
|
9
|
+
attr_accessor :status
|
10
|
+
|
11
|
+
def initialize options = {}
|
12
|
+
options = options.symbolize_keys
|
13
|
+
@action_class = options[:action_class]
|
14
|
+
@action_class = @action_class.constantize if String === @action_class
|
15
|
+
@config = options.fetch(:config, ActiveSupport::OrderedHash.new)
|
16
|
+
@status = options.fetch(:status, :initial).to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_action
|
20
|
+
@action_class.new.configure do |config|
|
21
|
+
config.replace(@config)
|
22
|
+
config.freeze
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json *options
|
27
|
+
to_h.to_json(*options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
{
|
32
|
+
action_class: @action_class.name,
|
33
|
+
config: @config,
|
34
|
+
status: @status,
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def == other
|
39
|
+
self.class == other.class && self.to_h == other.to_h
|
40
|
+
end
|
41
|
+
|
42
|
+
def status= new_status
|
43
|
+
old_status = @status
|
44
|
+
@status = new_status
|
45
|
+
broadcast :status_changed, self, new_status, old_status
|
46
|
+
@status
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
require "action/state/class_methods"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Action
|
2
|
+
class State
|
3
|
+
module ClassMethods
|
4
|
+
def sequence_status sequence
|
5
|
+
chunks = sequence.chunk{|status|status}
|
6
|
+
statuses = chunks.map(&:first)
|
7
|
+
chunks = chunks.map(&:last)
|
8
|
+
current = nil
|
9
|
+
case chunks.count
|
10
|
+
when 0
|
11
|
+
return :empty
|
12
|
+
when 1
|
13
|
+
status = statuses.first
|
14
|
+
return status if [:done, :planned].include?(status)
|
15
|
+
current = 0
|
16
|
+
when 2
|
17
|
+
current = if statuses.first == :done
|
18
|
+
1
|
19
|
+
elsif statuses.last == :planned
|
20
|
+
0
|
21
|
+
end
|
22
|
+
when 3
|
23
|
+
current = 1 if statuses.first == :done && statuses.last == :planned
|
24
|
+
end
|
25
|
+
if current
|
26
|
+
status = statuses[current]
|
27
|
+
if [:failed, :running].include?(status) && chunks[current].length == 1
|
28
|
+
return status
|
29
|
+
end
|
30
|
+
end
|
31
|
+
:invalid
|
32
|
+
end
|
33
|
+
end
|
34
|
+
extend ClassMethods
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action-plan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Artem Baguinski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: wisper
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.0.0.rc1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.0.0.rc1
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- abaguinski@depraktijkindex.nl
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- action-plan.gemspec
|
127
|
+
- bin/_guard-core
|
128
|
+
- bin/bundler
|
129
|
+
- bin/coderay
|
130
|
+
- bin/console
|
131
|
+
- bin/guard
|
132
|
+
- bin/htmldiff
|
133
|
+
- bin/launchy
|
134
|
+
- bin/ldiff
|
135
|
+
- bin/listen
|
136
|
+
- bin/pry
|
137
|
+
- bin/rake
|
138
|
+
- bin/rspec
|
139
|
+
- bin/setup
|
140
|
+
- bin/thor
|
141
|
+
- config/Guardfile
|
142
|
+
- lib/action/base.rb
|
143
|
+
- lib/action/plan.rb
|
144
|
+
- lib/action/plan/version.rb
|
145
|
+
- lib/action/state.rb
|
146
|
+
- lib/action/state/class_methods.rb
|
147
|
+
homepage: https://github.com/artm/action-plan
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.4.5.1
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Plan and eventually execute actions
|
171
|
+
test_files: []
|