hyper-operation 1.0.alpha1.5 → 1.0.0.lap28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -7
- data/.travis.yml +9 -20
- data/CODE_OF_CONDUCT.md +49 -0
- data/DOCS-POLICIES.md +582 -0
- data/DOCS.md +869 -0
- data/Gemfile +1 -5
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +2 -1
- data/dciy.toml +3 -0
- data/hyper-operation.gemspec +13 -16
- data/lib/hyper-operation.rb +5 -8
- data/lib/hyper-operation/api.rb +2 -2
- data/lib/hyper-operation/boot.rb +2 -3
- data/lib/hyper-operation/engine.rb +2 -2
- data/lib/hyper-operation/exception.rb +4 -30
- data/lib/hyper-operation/filters/acting_user.rb +1 -1
- data/lib/hyper-operation/http.rb +2 -2
- data/lib/hyper-operation/promise.rb +2 -28
- data/lib/hyper-operation/railway.rb +1 -1
- data/lib/hyper-operation/railway/dispatcher.rb +4 -8
- data/lib/hyper-operation/railway/params_wrapper.rb +2 -2
- data/lib/hyper-operation/railway/run.rb +49 -52
- data/lib/hyper-operation/railway/validations.rb +3 -10
- data/lib/hyper-operation/server_op.rb +19 -45
- data/lib/hyper-operation/transport/action_cable.rb +8 -8
- data/lib/hyper-operation/transport/client_drivers.rb +53 -94
- data/lib/hyper-operation/transport/connection.rb +10 -10
- data/lib/hyper-operation/transport/{hyperstack.rb → hyperloop.rb} +14 -19
- data/lib/hyper-operation/transport/{hyperstack_controller.rb → hyperloop_controller.rb} +52 -54
- data/lib/hyper-operation/transport/policy.rb +45 -41
- data/lib/hyper-operation/version.rb +2 -2
- data/lib/sources/{hyperstack → hyperloop}/pusher.js +0 -0
- metadata +51 -50
- data/lib/hyper-operation/transport/policy_diagnostics.rb +0 -106
data/Gemfile
CHANGED
@@ -1,7 +1,3 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'hyper-spec', path: '../hyper-spec'
|
4
|
-
gem 'hyperstack-config', path: '../hyperstack-config'
|
5
|
-
gem 'hyper-state', path: '../hyper-state'
|
6
|
-
gem 'hyper-component', path: '../hyper-component'
|
2
|
+
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
|
7
3
|
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Mitch VanDuyn
|
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,77 @@
|
|
1
|
+
<div class="githubhyperloopheader">
|
2
|
+
|
3
|
+
<p align="center">
|
4
|
+
|
5
|
+
<a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
|
6
|
+
<img width="350px" src="http://ruby-hyperloop.org/images/hyperloop-github-logo.png">
|
7
|
+
</a>
|
8
|
+
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<h2 align="center">The Complete Isomorphic Ruby Framework</h2>
|
12
|
+
|
13
|
+
<br>
|
14
|
+
|
15
|
+
<a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
|
16
|
+
<img src="http://ruby-hyperloop.org/images/githubhyperloopbadge.png">
|
17
|
+
</a>
|
18
|
+
|
19
|
+
<a href="https://gitter.im/ruby-hyperloop/chat" alt="Gitter chat" title="Gitter chat">
|
20
|
+
<img src="http://ruby-hyperloop.org/images/githubgitterbadge.png">
|
21
|
+
</a>
|
22
|
+
|
23
|
+
[![Build Status](https://travis-ci.org/ruby-hyperloop/hyper-operation.svg?branch=master)](https://travis-ci.org/ruby-hyperloop/hyper-operation)
|
24
|
+
[![Gem Version](https://badge.fury.io/rb/hyper-operation.svg)](https://badge.fury.io/rb/hyper-operation)
|
25
|
+
|
26
|
+
<p align="center">
|
27
|
+
<img src="http://ruby-hyperloop.org/images/HyperOperations.png" width="100" alt="Hyper-operation">
|
28
|
+
</p>
|
29
|
+
|
30
|
+
</div>
|
31
|
+
|
32
|
+
## Hyper-Operation GEM is part of Hyperloop GEMS family
|
33
|
+
|
34
|
+
Build interactive Web applications quickly. Hyperloop encourages rapid development with clean, pragmatic design. With developer productivity as our highest goal, Hyperloop takes care of much of the hassle of Web development, so you can focus on innovation and delivering end-user value.
|
35
|
+
|
36
|
+
One language. One model. One set of tests. The same business logic and domain models running on the clients and the server. Hyperloop is fully integrated with Rails and also gives you unfettered access to the complete universe of JavaScript libraries (including React) from within your Ruby code. Hyperloop lets you build beautiful interactive user interfaces in Ruby.
|
37
|
+
|
38
|
+
Everything has a place in our architecture. Components deliver interactive user experiences, Operations encapsulate business logic, Models magically synchronize data between clients and servers, Policies govern authorization and Stores hold local state.
|
39
|
+
|
40
|
+
**Hyper-Operation** brings Operations which encapsulate business logic. In a traditional MVC architecture, Operations end up either in Controllers, Models or some other secondary construct such as service objects, helpers, or concerns. Here they are first class objects. Their job is to mutate state in the Stores and Models.
|
41
|
+
|
42
|
+
## Getting Started
|
43
|
+
|
44
|
+
1. Update your Gemfile:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
#Gemfile
|
48
|
+
|
49
|
+
gem 'hyperloop'
|
50
|
+
```
|
51
|
+
|
52
|
+
2. At the command prompt, update your bundle :
|
53
|
+
|
54
|
+
$ bundle update
|
55
|
+
|
56
|
+
3. Run the hyperloop install generator:
|
57
|
+
|
58
|
+
$ rails g hyperloop:install
|
59
|
+
|
60
|
+
4. Follow the guidelines to start developing your application. You may find
|
61
|
+
the following resources handy:
|
62
|
+
* [Getting Started with Hyperloop](http://ruby-hyperloop.org/start/components/)
|
63
|
+
* [Hyperloop Guides](http://ruby-hyperloop.org/docs/architecture)
|
64
|
+
* [Hyperloop Tutorial](http://ruby-hyperloop.org/tutorials)
|
65
|
+
|
66
|
+
## Community
|
67
|
+
|
68
|
+
#### Getting Help
|
69
|
+
Please **do not post** usage questions to GitHub Issues. For these types of questions use our [Gitter chatroom](https://gitter.im/ruby-hyperloop/chat) or [StackOverflow](http://stackoverflow.com/questions/tagged/hyperloop).
|
70
|
+
|
71
|
+
#### Submitting Bugs and Enhancements
|
72
|
+
[GitHub Issues](https://github.com/ruby-hyperloop/hyperloop/issues) is for suggesting enhancements and reporting bugs. Before submiting a bug make sure you do the following:
|
73
|
+
* Check out our [contributing guide](https://github.com/ruby-hyperloop/hyperloop/blob/master/CONTRIBUTING.md) for info on our release cycle.
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
Hyperloop is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/dciy.toml
ADDED
data/hyper-operation.gemspec
CHANGED
@@ -5,39 +5,36 @@ require 'hyper-operation/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'hyper-operation'
|
8
|
-
spec.version =
|
8
|
+
spec.version = Hyperloop::Operation::VERSION
|
9
9
|
spec.authors = ['Mitch VanDuyn', 'Jan Biedermann']
|
10
10
|
spec.email = ['mitch@catprint.com', 'jan@kursator.com']
|
11
|
-
spec.summary =
|
12
|
-
spec.homepage = 'http://ruby-
|
11
|
+
spec.summary = %q{Compose your business logic into isomorphic commands that sanitize and validate input. Write safe, reusable, and maintainable code for Ruby and Rails app}
|
12
|
+
spec.homepage = 'http://ruby-hyperloop.org'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
# spec.metadata = {
|
15
|
-
# "homepage_uri" => 'http://ruby-
|
16
|
-
# "source_code_uri" => 'https://github.com/ruby-
|
15
|
+
# "homepage_uri" => 'http://ruby-hyperloop.org',
|
16
|
+
# "source_code_uri" => 'https://github.com/ruby-hyperloop/hyper-component'
|
17
17
|
# }
|
18
18
|
|
19
|
-
spec.files = `git ls-files -z
|
20
|
-
.split("\x0")
|
21
|
-
.reject { |f| f.match(%r{^(gemfiles|examples|spec)/}) }
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(gemfiles|examples|spec)/}) }
|
22
20
|
spec.bindir = 'exe'
|
23
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
22
|
spec.require_paths = ['lib']
|
25
23
|
|
26
24
|
spec.add_dependency 'activerecord', '>= 4.0.0'
|
27
|
-
spec.add_dependency 'hyper-component',
|
25
|
+
spec.add_dependency 'hyper-component', Hyperloop::Operation::VERSION
|
26
|
+
spec.add_dependency 'hyperloop-config', Hyperloop::Operation::VERSION
|
28
27
|
spec.add_dependency 'mutations'
|
29
28
|
spec.add_dependency 'opal-activesupport', '~> 0.3.1'
|
30
|
-
spec.
|
31
|
-
|
32
|
-
spec.add_development_dependency 'bundler', ['>= 1.17.3', '< 2.1']
|
33
|
-
spec.add_development_dependency 'chromedriver-helper'
|
29
|
+
spec.add_development_dependency 'bundler'
|
34
30
|
spec.add_development_dependency 'database_cleaner'
|
35
|
-
spec.add_development_dependency 'hyper-
|
31
|
+
spec.add_development_dependency 'hyper-react', Hyperloop::Operation::VERSION
|
32
|
+
spec.add_development_dependency 'hyper-spec', Hyperloop::Operation::VERSION
|
36
33
|
spec.add_development_dependency 'mysql2'
|
37
34
|
spec.add_development_dependency 'opal', '>= 0.11.0', '< 0.12.0'
|
38
35
|
spec.add_development_dependency 'opal-browser', '~> 0.2.0'
|
39
36
|
spec.add_development_dependency 'opal-rails', '~> 0.9.4'
|
40
|
-
spec.add_development_dependency '
|
37
|
+
spec.add_development_dependency 'mini_racer', '~> 0.1.15'
|
41
38
|
spec.add_development_dependency 'puma'
|
42
39
|
spec.add_development_dependency 'pusher'
|
43
40
|
spec.add_development_dependency 'pusher-fake'
|
@@ -47,6 +44,6 @@ Gem::Specification.new do |spec|
|
|
47
44
|
spec.add_development_dependency 'rspec-rails'
|
48
45
|
spec.add_development_dependency 'rspec-steps', '~> 2.1.1'
|
49
46
|
spec.add_development_dependency 'rspec-wait'
|
50
|
-
spec.add_development_dependency 'sqlite3'
|
47
|
+
spec.add_development_dependency 'sqlite3'
|
51
48
|
spec.add_development_dependency 'timecop', '~> 0.8.1'
|
52
49
|
end
|
data/lib/hyper-operation.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'hyper-operation/version'
|
2
|
-
require '
|
2
|
+
require 'hyperloop-config'
|
3
3
|
|
4
|
-
|
4
|
+
Hyperloop.import 'hyper-operation'
|
5
5
|
|
6
6
|
if RUBY_ENGINE == 'opal'
|
7
7
|
require 'active_support/core_ext/string'
|
@@ -29,8 +29,7 @@ if RUBY_ENGINE == 'opal'
|
|
29
29
|
require 'hyper-operation/server_op'
|
30
30
|
require 'hyper-operation/boot'
|
31
31
|
else
|
32
|
-
require '
|
33
|
-
require 'hyperstack-config'
|
32
|
+
require 'hyperloop-config'
|
34
33
|
require 'mutations'
|
35
34
|
Mutations::HashFilter.register_additional_filter(Mutations::DuckFilter, :duck)
|
36
35
|
require 'hyper-operation/filters/outbound_filter'
|
@@ -39,9 +38,8 @@ else
|
|
39
38
|
require 'hyper-operation/transport/active_record'
|
40
39
|
require 'hyper-operation/engine'
|
41
40
|
require 'hyper-operation/transport/connection'
|
42
|
-
require 'hyper-operation/transport/
|
41
|
+
require 'hyper-operation/transport/hyperloop'
|
43
42
|
require 'hyper-operation/transport/policy'
|
44
|
-
require 'hyper-operation/transport/policy_diagnostics'
|
45
43
|
require 'hyper-operation/transport/client_drivers'
|
46
44
|
require 'hyper-operation/transport/acting_user'
|
47
45
|
require 'opal-activesupport'
|
@@ -54,9 +52,8 @@ else
|
|
54
52
|
require 'hyper-operation/railway/params_wrapper'
|
55
53
|
require 'hyper-operation/railway/run.rb'
|
56
54
|
require 'hyper-operation/railway/validations'
|
57
|
-
require 'hyper-operation/transport/
|
55
|
+
require 'hyper-operation/transport/hyperloop_controller'
|
58
56
|
require 'hyper-operation/server_op'
|
59
|
-
require 'hyper-operation/boot'
|
60
57
|
Opal.use_gem 'mutations', false
|
61
58
|
Opal.append_path File.expand_path('../sources/', __FILE__).untaint
|
62
59
|
Opal.append_path File.expand_path('../', __FILE__).untaint
|
data/lib/hyper-operation/api.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Hyperloop
|
2
2
|
class Operation
|
3
3
|
|
4
4
|
def add_error(key, kind, message = nil)
|
@@ -137,7 +137,7 @@ module Hyperstack
|
|
137
137
|
end
|
138
138
|
|
139
139
|
child.singleton_class.define_singleton_method(:_Railway) do
|
140
|
-
|
140
|
+
Hyperloop::Context.set_var(self, :@_railway) do
|
141
141
|
# overcomes a bug in Opal 0.9 which returns nil for singleton superclass
|
142
142
|
my_super = superclass || `self.$$singleton_of`.superclass.singleton_class
|
143
143
|
if my_super == Operation.singleton_class
|
data/lib/hyper-operation/boot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
# Tricky business here.
|
1
|
+
module Hyperloop
|
2
|
+
# Tricky business here. Hyperloop::Store will define boot
|
3
3
|
# if it is not already defined. It creates a minimal compatible
|
4
4
|
# API that includes the run and on_dispatch methods. This way
|
5
5
|
# you can use the Boot interface without loading operations.
|
@@ -11,7 +11,6 @@ module Hyperstack
|
|
11
11
|
class Application
|
12
12
|
Operation.inherited(Boot) if defined? Boot
|
13
13
|
class Boot < Operation
|
14
|
-
#broadcaster.receiver(self, *args, &block)
|
15
14
|
def self.on_dispatch(&block)
|
16
15
|
_Railway.add_receiver(&block)
|
17
16
|
end
|
@@ -1,39 +1,13 @@
|
|
1
|
-
module
|
2
|
-
class ErrorArray
|
3
|
-
def self.new_from_error_hash(errors)
|
4
|
-
new(errors.collect do |key, values|
|
5
|
-
ErrorAtom.new(key, values[:symbol], values)
|
6
|
-
end)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module Hyperstack
|
1
|
+
module Hyperloop
|
12
2
|
class AccessViolation < StandardError
|
13
|
-
|
14
|
-
|
15
|
-
def initialize(message = nil, details = nil)
|
16
|
-
super("Hyperstack::AccessViolation#{':' + message.to_s if message}")
|
17
|
-
@details = details
|
18
|
-
end
|
19
|
-
|
20
|
-
def __hyperstack_on_error(operation, params, fmted_message)
|
21
|
-
Hyperstack.on_error(operation, self, params, fmted_message)
|
3
|
+
def message
|
4
|
+
"Hyperloop::Operation::AccessViolation: #{super}"
|
22
5
|
end
|
23
6
|
end
|
24
7
|
|
25
8
|
class Operation
|
26
9
|
class ValidationException < Mutations::ValidationException
|
27
|
-
def as_json(*)
|
28
|
-
errors.as_json
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize(errors)
|
32
|
-
unless errors.is_a? Mutations::ErrorHash
|
33
|
-
errors = Mutations::ErrorArray.new_from_error_hash(errors)
|
34
|
-
end
|
35
|
-
super(errors)
|
36
|
-
end
|
37
10
|
end
|
38
11
|
end
|
12
|
+
|
39
13
|
end
|
data/lib/hyper-operation/http.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Hyperloop
|
2
2
|
# {HTTP} is used to perform a `XMLHttpRequest` in ruby. It is a simple wrapper
|
3
3
|
# around `XMLHttpRequest`
|
4
4
|
#
|
@@ -161,7 +161,7 @@ module Hyperstack
|
|
161
161
|
@active_requests ||= 0
|
162
162
|
@active_requests -= 1
|
163
163
|
if @active_requests < 0
|
164
|
-
`console.log("Ooops,
|
164
|
+
`console.log("Ooops, Hyperloop::HTTP active_requests out of sync!")`
|
165
165
|
@active_requests = 0
|
166
166
|
end
|
167
167
|
end
|
@@ -1,15 +1,3 @@
|
|
1
|
-
# Caution. For now Hyperstack maintains its own copy of the Promise class.
|
2
|
-
# Eventually the diff between hyperstacks version and the official Opal version
|
3
|
-
# should be put into a PR.
|
4
|
-
|
5
|
-
# A key feature add is the Fail Exception class which is simply there to allow
|
6
|
-
# a `always` block to reject without raising an error. To use this see the run.rb
|
7
|
-
# module.
|
8
|
-
|
9
|
-
# Also see exception! method for the part of the code that detects the Fail exception.
|
10
|
-
|
11
|
-
# See https://github.com/opal/opal/issues/1967 for details.
|
12
|
-
|
13
1
|
class Promise
|
14
2
|
def self.value(value)
|
15
3
|
new.resolve(value)
|
@@ -23,13 +11,6 @@ class Promise
|
|
23
11
|
When.new(promises)
|
24
12
|
end
|
25
13
|
|
26
|
-
class Fail < StandardError
|
27
|
-
attr_reader :result
|
28
|
-
def initialize(result)
|
29
|
-
@result = result
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
14
|
attr_reader :error, :prev, :next
|
34
15
|
|
35
16
|
def initialize(action = {})
|
@@ -183,15 +164,8 @@ class Promise
|
|
183
164
|
end
|
184
165
|
|
185
166
|
def exception!(error)
|
186
|
-
|
187
|
-
|
188
|
-
# this allows code to raise an error on an
|
189
|
-
# object that is not an error.
|
190
|
-
if error.is_a? Promise::Fail
|
191
|
-
error = error.result
|
192
|
-
else
|
193
|
-
@exception = true
|
194
|
-
end
|
167
|
+
@exception = true
|
168
|
+
|
195
169
|
reject!(error)
|
196
170
|
end
|
197
171
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Hyperloop
|
2
2
|
class Operation
|
3
3
|
class Railway
|
4
4
|
|
@@ -9,16 +9,12 @@ module Hyperstack
|
|
9
9
|
class << self
|
10
10
|
def receivers
|
11
11
|
# use the force: true option so that system code needing to receive
|
12
|
-
# boot will NOT be erased on the next
|
13
|
-
|
12
|
+
# boot will NOT be erased on the next Hyperloop::Context.reset!
|
13
|
+
Hyperloop::Context.set_var(self, :@receivers, force: true) { [] }
|
14
14
|
end
|
15
15
|
|
16
16
|
def add_receiver(&block)
|
17
|
-
|
18
|
-
operation = self
|
19
|
-
cloned_block.define_singleton_method(:unmount) { operation.receivers.delete(cloned_block) }
|
20
|
-
receivers << cloned_block
|
21
|
-
cloned_block
|
17
|
+
receivers << block
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Hyperloop
|
2
2
|
class Operation
|
3
3
|
class ParamsWrapper
|
4
4
|
|
@@ -119,7 +119,7 @@ module Hyperstack
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def self.params_wrapper
|
122
|
-
|
122
|
+
Hyperloop::Context.set_var(self, :@params_wrapper) do
|
123
123
|
if Railway == superclass
|
124
124
|
Class.new(ParamsWrapper)
|
125
125
|
else
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Hyperloop
|
2
2
|
class Operation
|
3
3
|
|
4
4
|
class Exit < StandardError
|
@@ -21,7 +21,7 @@ module Hyperstack
|
|
21
21
|
@tracks ||= []
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def to_opts(tie, args, block)
|
25
25
|
if args.count.zero?
|
26
26
|
{ run: block }
|
27
27
|
elsif args[0].is_a?(Hash)
|
@@ -41,7 +41,7 @@ module Hyperstack
|
|
41
41
|
|
42
42
|
[:step, :failed, :async].each do |tie|
|
43
43
|
define_method :"add_#{tie}" do |*args, &block|
|
44
|
-
tracks <<
|
44
|
+
tracks << to_opts(tie, args, block)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -55,33 +55,44 @@ module Hyperstack
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def step(opts)
|
58
|
-
@
|
59
|
-
.then
|
58
|
+
if @last_result.is_a? Promise
|
59
|
+
@last_result = @last_result.then do |*result|
|
60
|
+
@last_result = result
|
61
|
+
apply(opts, :in_promise)
|
62
|
+
end
|
63
|
+
elsif @state == :success
|
64
|
+
apply(opts)
|
65
|
+
end
|
60
66
|
end
|
61
67
|
|
62
68
|
def failed(opts)
|
63
|
-
@
|
64
|
-
.
|
69
|
+
if @last_result.is_a? Promise
|
70
|
+
@last_result = @last_result.fail do |e|
|
71
|
+
@last_result = e
|
72
|
+
apply(opts, :in_promise)
|
73
|
+
raise @last_result if @last_result.is_a? Exception
|
74
|
+
raise e
|
75
|
+
end
|
76
|
+
elsif @state == :failed
|
77
|
+
apply(opts)
|
78
|
+
end
|
65
79
|
end
|
66
80
|
|
67
81
|
def async(opts)
|
68
|
-
|
69
|
-
@promise_chain.resolve(@last_async_result)
|
70
|
-
step(opts)
|
82
|
+
apply(opts) if @state != :failed
|
71
83
|
end
|
72
84
|
|
73
|
-
def apply(
|
74
|
-
return result unless @state == state
|
85
|
+
def apply(opts, in_promise = nil)
|
75
86
|
if opts[:scope] == :class
|
76
|
-
args = [@operation,
|
87
|
+
args = [@operation, *@last_result]
|
77
88
|
instance = @operation.class
|
78
89
|
else
|
79
|
-
args =
|
90
|
+
args = @last_result
|
80
91
|
instance = @operation
|
81
92
|
end
|
82
93
|
block = opts[:run]
|
83
94
|
block = instance.method(block) if block.is_a? Symbol
|
84
|
-
last_result =
|
95
|
+
@last_result =
|
85
96
|
if block.arity.zero?
|
86
97
|
instance.instance_exec(&block)
|
87
98
|
elsif args.is_a?(Array) && block.arity == args.count
|
@@ -89,54 +100,40 @@ module Hyperstack
|
|
89
100
|
else
|
90
101
|
instance.instance_exec(args, &block)
|
91
102
|
end
|
92
|
-
@
|
93
|
-
last_result
|
103
|
+
return @last_result unless @last_result.is_a? Promise
|
104
|
+
raise @last_result.error if @last_result.rejected?
|
105
|
+
@last_result = @last_result.value if @last_result.resolved?
|
106
|
+
@last_result
|
94
107
|
rescue Exit => e
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
# :succeed or :failed
|
99
|
-
if e.state == :failed
|
100
|
-
@state = :abort
|
101
|
-
# exit via the final always block with the exception
|
102
|
-
raise e.result.is_a?(Exception) ? e.result : e
|
103
|
-
else
|
104
|
-
@state = :succeed
|
105
|
-
# exit via the final then block with the success value
|
106
|
-
e.result
|
107
|
-
end
|
108
|
+
@state = e.state
|
109
|
+
@last_result = (e.state != :failed || e.result.is_a?(Exception)) ? e.result : e
|
110
|
+
raise e
|
108
111
|
rescue Exception => e
|
109
112
|
@state = :failed
|
110
|
-
|
113
|
+
@last_result = e
|
114
|
+
raise e if in_promise
|
111
115
|
end
|
112
116
|
|
113
117
|
def run
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
@promise_chain_start = @promise_chain = Promise.new
|
124
|
-
@promise_chain_start.resolve(@last_result)
|
125
|
-
tracks.each { |opts| opts[:tie].bind(self).call(opts) } unless @state == :abort
|
118
|
+
if @operation.has_errors? || @state
|
119
|
+
@last_result ||= ValidationException.new(@operation.instance_variable_get('@errors'))
|
120
|
+
return if @state # handles abort out of validation
|
121
|
+
@state = :failed
|
122
|
+
else
|
123
|
+
@state = :success
|
124
|
+
end
|
125
|
+
tracks.each { |opts| opts[:tie].bind(self).call(opts) }
|
126
|
+
rescue Exit
|
126
127
|
end
|
127
128
|
|
128
129
|
def result
|
129
|
-
@
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
else
|
134
|
-
raise Promise::Fail.new(e)
|
135
|
-
end
|
130
|
+
return @last_result if @last_result.is_a? Promise
|
131
|
+
@last_result =
|
132
|
+
if @state == :success
|
133
|
+
Promise.new.resolve(@last_result)
|
136
134
|
else
|
137
|
-
|
135
|
+
Promise.new.reject(@last_result)
|
138
136
|
end
|
139
|
-
end
|
140
137
|
end
|
141
138
|
end
|
142
139
|
end
|