w_flow 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea684020b144fcbcb694e2c1df80e7d9244cfd35
4
+ data.tar.gz: abee114f93512251d671e246fd8a8fdc34dce351
5
+ SHA512:
6
+ metadata.gz: 8545ebdf9cd7f084c2a377229807575331e591e4ca0180505657b10f1e6568c20dd9416768f4d46456c33909220b3a43d3573051f91c3f827d8c5ea399dbd9d3
7
+ data.tar.gz: 0de1290ab22238663fe1ccc87778ede829b15bb6903dca93218ed01e08caac161f8b579d80fc8f18b1943be5b458e524139fbc4d160e547e633cb4c4e62339ec
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .ruby-gemset
12
+
13
+ .ruby-version
14
+
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --format html -o "tmp/rspec.html"
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.1.1
5
+ - 2.0.0
6
+ script: bundle exec rspec
7
+ before_install: gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in w_flow.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # WFlow
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rekiq.svg)](http://badge.fury.io/rb/rekiq)
4
+ [![Build Status](https://travis-ci.org/junhanamaki/rekiq.svg?branch=master)](https://travis-ci.org/junhanamaki/rekiq)
5
+ [![Code Climate](https://codeclimate.com/github/junhanamaki/rekiq.png)](https://codeclimate.com/github/junhanamaki/rekiq)
6
+ [![Test Coverage](https://codeclimate.com/github/junhanamaki/rekiq/coverage.png)](https://codeclimate.com/github/junhanamaki/rekiq)
7
+ [![Dependency Status](https://gemnasium.com/junhanamaki/rekiq.svg)](https://gemnasium.com/junhanamaki/rekiq)
8
+
9
+ ## Dependencies
10
+
11
+ Tested with:
12
+
13
+ * ruby 2.2.0, 2.1.1, 2.0.0
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'w_flow'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install w_flow
30
+
31
+ ## Usage
32
+
33
+ TODO: Write usage instructions here
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/w_flow/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ module WFlow
2
+ class Data
3
+ def initialize(data)
4
+ @data = data
5
+ end
6
+
7
+ protected
8
+
9
+ def method_missing(method_name, *args, &block)
10
+ method_name = method_name.to_s
11
+
12
+ if method_name[-1] == '='
13
+ @data[method_name[0..-2].to_sym] = args[0]
14
+ else
15
+ @data[method_name.to_sym]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module WFlow
2
+ class StandardError < ::StandardError; end
3
+
4
+ class InvalidArgument < StandardError; end
5
+ class FlowFailure < StandardError; end
6
+ class UnknownTask < StandardError; end
7
+ end
@@ -0,0 +1,32 @@
1
+ module WFlow
2
+ class Flow
3
+ attr_reader :data, :failure_message
4
+
5
+ def initialize(data)
6
+ @data = Data.new(data)
7
+ @failure = false
8
+ @failure_message = nil
9
+ end
10
+
11
+ def success?
12
+ !failure?
13
+ end
14
+
15
+ def failure?
16
+ @failure
17
+ end
18
+
19
+ def failure!(message = nil)
20
+ @failure = true
21
+ @failure_message = message
22
+ end
23
+
24
+ def stop!
25
+ throw :stop
26
+ end
27
+
28
+ def skip!
29
+ throw :skip
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ module WFlow
2
+ module Process
3
+ attr_reader :flow
4
+
5
+ def initialize(flow)
6
+ @flow = flow
7
+ end
8
+
9
+ def setup; end
10
+ def perform; end
11
+ def rollback; end
12
+ def final; end
13
+
14
+ def self.included(klass)
15
+ klass.extend(ClassMethods)
16
+
17
+ klass.instance_variable_set('@process_nodes', [])
18
+ end
19
+
20
+ module ClassMethods
21
+ def data_accessor(*keys)
22
+ data_writer(keys)
23
+ data_reader(keys)
24
+ end
25
+
26
+ def data_writer(*keys)
27
+ keys.each do |key|
28
+ define_method "#{key}=" do |val|
29
+ flow.data[key] = val
30
+ end
31
+ end
32
+ end
33
+
34
+ def data_reader(*keys)
35
+ keys.each do |key|
36
+ define_method key do
37
+ flow.data[key]
38
+ end
39
+ end
40
+ end
41
+
42
+ def execute(*args)
43
+ options = args.pop if args.last.is_a?(Hash)
44
+ args << Proc.new if block_given?
45
+
46
+ @process_nodes << ProcessNode.new(args, options)
47
+ end
48
+
49
+ def run(params = {})
50
+ unless params.is_a?(Hash)
51
+ raise InvalidArgument, 'run must be invoked with an Hash'
52
+ end
53
+ end
54
+
55
+ def run_as_dependency(flow)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,45 @@
1
+ module WFlow
2
+ class ProcessNode
3
+ def initialize(tasks, options)
4
+ @tasks = tasks
5
+ @options = options
6
+ end
7
+
8
+ def execute(owner_process)
9
+ return unless execute_node?(owner_process)
10
+
11
+ @tasks.each do |task|
12
+ if task.is_a?(String) || task.is_a?(Symbol)
13
+ owner_process.instance_eval(task.to_s)
14
+ elsif task.is_a?(Proc)
15
+ owner_process.instance_eval(&task)
16
+ elsif task.is_a?(Process)
17
+ task.run(owner_process.flow)
18
+ else
19
+ raise UnknownTask, "don't know how to execute task #{task}"
20
+ end
21
+ end
22
+ end
23
+
24
+ protected
25
+
26
+ def execute_node?(owner_process)
27
+ if_condition_allows_execution?(owner_process) &&
28
+ unless_condition_allows_execution?(owner_process)
29
+ end
30
+
31
+ def if_condition_allows_execution?(owner_process)
32
+ @options[:if].nil? || eval_condition(@options[:if], owner_process)
33
+ end
34
+
35
+ def unless_condition_allows_execution?(owner_process)
36
+ @options[:unless].nil? || !eval_condition(@options[:unless], owner_process)
37
+ end
38
+
39
+ def eval_condition?(condition, owner_process)
40
+ ((condition.is_a?(String) || condition.is_a?(Symbol)) &&
41
+ owner_process.instance_eval(condition.to_s)) ||
42
+ (condition.is_a?(Proc) && owner_process.instance_eval(&condition))
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module WFlow
2
+ VERSION = "0.1.0"
3
+ end
data/lib/w_flow.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "w_flow/version"
2
+ require 'w_flow/exceptions'
3
+ require 'w_flow/data'
4
+ require 'w_flow/flow'
5
+ require 'w_flow/process_node'
6
+ require 'w_flow/process'
7
+
8
+ module WFlow
9
+ end
data/w_flow.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'w_flow/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "w_flow"
8
+ spec.version = WFlow::VERSION
9
+ spec.authors = ["junhanamaki"]
10
+ spec.email = ["jun.hanamaki@gmail.com"]
11
+
12
+ spec.summary = %q{A workflow composer based on Single Responsability Principle to help organize projects}
13
+ spec.description = %q{WFlow is a workflow composer that helps in organizing projects by splitting logic into reusable modules (processes)}
14
+ spec.homepage = "https://github.com/junhanamaki/w_flow"
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rspec", '~> 3.2'
24
+ spec.add_development_dependency "pry", '~> 0.10'
25
+ spec.add_development_dependency 'simplecov', '~> 0.10'
26
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
27
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: w_flow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - junhanamaki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-10 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
83
+ description: WFlow is a workflow composer that helps in organizing projects by splitting
84
+ logic into reusable modules (processes)
85
+ email:
86
+ - jun.hanamaki@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - lib/w_flow.rb
98
+ - lib/w_flow/data.rb
99
+ - lib/w_flow/exceptions.rb
100
+ - lib/w_flow/flow.rb
101
+ - lib/w_flow/process.rb
102
+ - lib/w_flow/process_node.rb
103
+ - lib/w_flow/version.rb
104
+ - w_flow.gemspec
105
+ homepage: https://github.com/junhanamaki/w_flow
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.5
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A workflow composer based on Single Responsability Principle to help organize
129
+ projects
130
+ test_files: []