Skip to content

Commit

Permalink
Merge pull request #29 from differencialx/alpha3
Browse files Browse the repository at this point in the history
Alpha3
  • Loading branch information
differencialx committed Jun 9, 2022
2 parents c51f4f5 + 550b326 commit 06d2ffd
Show file tree
Hide file tree
Showing 43 changed files with 3,254 additions and 495 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Or install it by yourself:
- [Wrap](https://github.com/differencialx/decouplio/blob/master/docs/wrap.md)
- [Resq](https://github.com/differencialx/decouplio/blob/master/docs/resq.md)
- [Inner action](https://github.com/differencialx/decouplio/blob/master/docs/inner_action.md)
- [Doby/Deny](https://github.com/differencialx/decouplio/blob/master/docs/doby_deny.md)
- [Doby/Aide](https://github.com/differencialx/decouplio/blob/master/docs/doby_aide.md)
- [Step as a service](https://github.com/differencialx/decouplio/blob/master/docs/step_as_a_service.md)
- [Error store](https://github.com/differencialx/decouplio/blob/master/docs/error_store.md)
- [Benchmarks](https://github.com/differencialx/decouplio/blob/master/docs/benchmarks.md)
Expand Down
21 changes: 11 additions & 10 deletions benchmarks/multi_step_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def call
step_seven
step_eight
step_nine
self
end

def step_one
Expand Down Expand Up @@ -253,55 +254,55 @@ def step_nine(ctx, step_eight:, **)
end

class DecouplioStepOne
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_one] = ctx[:param1]
end
end

class DecouplioStepTwo
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_two] = ctx[:step_one]
end
end

class DecouplioStepThree
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_three] = ctx[:step_two]
end
end

class DecouplioStepFour
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_four] = ctx[:step_three]
end
end

class DecouplioStepFive
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_five] = ctx[:step_four]
end
end

class DecouplioStepSix
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_six] = ctx[:step_five]
end
end

class DecouplioStepSeven
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_seven] = ctx[:step_six]
end
end

class DecouplioStepEight
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_eight] = ctx[:step_seven]
end
end

class DecouplioStepNine
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_nine] = ctx[:step_eight]
end
end
Expand All @@ -320,7 +321,7 @@ class DecouplioServiceStepsTest < Decouplio::Action
end
end

iteration_count = 100_000_0
iteration_count = 100_00

Benchmark.ips do |x|
x.report('RegularService') { iteration_count.times { RegularServiceTest.call(param1: 'param1') } }
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/single_step_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def step_one(ctx, param1:, **)
end

class ServiceAsStep
def self.call(ctx:)
def self.call(ctx:, **)
ctx[:step_one] = ctx[:param1]
ctx[:step_two] = ctx[:step_one]
ctx[:step_three] = ctx[:step_two]
Expand Down
6 changes: 3 additions & 3 deletions docs/deny.rb → docs/aide.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative '../lib/decouplio'

class SemanticDeny
class SemanticAide
def self.call(ctx:, error_store:, semantic:, error_message:)
ctx[:semantic] = semantic
error_store.add_error(semantic, error_message)
Expand All @@ -10,7 +10,7 @@ def self.call(ctx:, error_store:, semantic:, error_message:)
class SomeAction < Decouplio::Action
logic do
step :step_one
deny SemanticDeny, semantic: :bad_request, error_message: 'Bad request'
aide SemanticAide, semantic: :bad_request, error_message: 'Bad request'
step :step_two
end

Expand Down Expand Up @@ -48,7 +48,7 @@ def fail_one(**)
# Result: failure

# Railway Flow:
# step_one -> SemanticDeny
# step_one -> SemanticAide

# Context:
# :step_one_param => false
Expand Down
61 changes: 49 additions & 12 deletions docs/doby_deny.md → docs/doby_aide.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Doby/Deny
# Doby/Aide

It's a step type to make configurable manipulations with action context.
Steps which make configurable manipulations with action context.


## Signature

```ruby
doby(class_constant, **options)
deny(class_constant, **options)
aide(class_constant, **options)
```

## Behavior
Expand All @@ -18,9 +18,9 @@ deny(class_constant, **options)
- `doby` doesn't have `on_success, on_failure, if, unless, finish_him` options.
- All options passed after class constant will be passed as kwargs for `.call` method.

### Deny
- `deny` behaves similar to `fail`, no matter which value will be returned by `.call` method, it moves to `failure` track.
- `deny` doesn't have `on_success, on_failure, if, unless, finish_him` options.
### Aide
- `aide` behaves similar to `fail`, no matter which value will be returned by `.call` method, it moves to `failure` track.
- `aide` doesn't have `on_success, on_failure, if, unless, finish_him` options.
- All options passed after class constant will be passed as kwargs for `.call` method.


Expand Down Expand Up @@ -49,7 +49,7 @@ end

# OR

class SemanticDeny
class SemanticAide
def self.call(ctx:, error_store:, semantic:, error_message:)
ctx[:semantic] = semantic
error_store.add_error(semantic, error_message)
Expand Down Expand Up @@ -81,7 +81,7 @@ end
class SomeAction < Decouplio::Action
logic do
step :user
step AssignDoby, to: :current_user, from: :user
doby AssignDoby, to: :current_user, from: :user
end

def user(id:, **)
Expand All @@ -107,11 +107,11 @@ action # =>
# Errors:
# {}
```
`SemanticDeny` example.
`SemanticAide` example.
```ruby
require 'decouplio'

class SemanticDeny
class SemanticAide
def self.call(ctx:, error_store:, semantic:, error_message:)
ctx[:semantic] = semantic
error_store.add_error(semantic, error_message)
Expand All @@ -121,7 +121,7 @@ end
class SomeAction < Decouplio::Action
logic do
step :step_one
deny SemanticDeny, semantic: :bad_request, error_message: 'Bad request'
aide SemanticAide, semantic: :bad_request, error_message: 'Bad request'
step :step_two
end

Expand Down Expand Up @@ -159,7 +159,7 @@ failure_action # =>
# Result: failure

# Railway Flow:
# step_one -> SemanticDeny
# step_one -> SemanticAide

# Context:
# :step_one_param => false
Expand All @@ -169,3 +169,40 @@ failure_action # =>
# Errors:
# :bad_request => ["Bad request"]
```


## Options

### Doby
Has the same options and behavior as [step](https://github.com/differencialx/decouplio/blob/master/docs/step.md), just specify them along with doby class options like here:
```ruby
# ...

logic do
doby AssignDoby,
to: :current_user,
from: :user,
on_success: :finish_him,
if: :condition
end

# ...
```

### Aide
Has the same options and behavior as [fail](https://github.com/differencialx/decouplio/blob/master/docs/fail.md), just specify them along with aide class options like here:

```ruby
# ...

logic do
step :step_one
aide SemanticAide,
semantic: :bad_request,
error_message: 'Bad request',
on_failure: :PASS,
unless: :condition
end

# ...
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Decouplio is a zero dependency, thread safe and framework agnostic gem designed
- [Wrap](https://github.com/differencialx/decouplio/blob/master/docs/wrap.md)
- [Resq](https://github.com/differencialx/decouplio/blob/master/docs/resq.md)
- [Inner action](https://github.com/differencialx/decouplio/blob/master/docs/inner_action.md)
- [Doby](https://github.com/differencialx/decouplio/blob/master/docs/doby.md)
- [Doby/Aide](https://github.com/differencialx/decouplio/blob/master/docs/doby_aide.md)
- [Step as a service](https://github.com/differencialx/decouplio/blob/master/docs/step_as_a_service.md)
- [Error store](https://github.com/differencialx/decouplio/blob/master/docs/error_store.md)
- [Benchmarks](https://github.com/differencialx/decouplio/blob/master/docs/benchmarks.md)
4 changes: 4 additions & 0 deletions docs/logic_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ Possible logic steps:
|octo|[--->>>](https://github.com/differencialx/decouplio/blob/master/docs/octo.md)|
|wrap|[--->>>](https://github.com/differencialx/decouplio/blob/master/docs/wrap.md)|
|resq|[--->>>](https://github.com/differencialx/decouplio/blob/master/docs/resq.md)|
|doby|[--->>>](https://github.com/differencialx/decouplio/blob/master/docs/doby_aide.md)|
|aide|[--->>>](https://github.com/differencialx/decouplio/blob/master/docs/doby_aide.md)|
|inner action|[--->>>](https://github.com/differencialx/decouplio/blob/master/docs/inner_action.md)|
|step as service|[--->>>](https://github.com/differencialx/decouplio/blob/master/docs/step_as_a_service.md)|
61 changes: 59 additions & 2 deletions docs/octo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ It's a step type which helps to implement strategy pattern.
## Signature

```ruby
octo(octo_name, ctx_key:, **options) do
octo(octo_name, ctx_key:, method:, **options) do
on :key1, palp: :palp_name_one
on :key2, palp: :palp_name_two
on :key3, palp: :palp_name_three
Expand All @@ -14,7 +14,11 @@ end

## Behavior

- depending on the value inside `ctx_key` in context `octo` will perform flow defined for this key. So basically `octo` will be replaces with flow you defined.
- Depending on some value you can perform different flow. Imagine that `octo` will be replaced with another flow.
- You have two options to set value for octo. By `ctx_key` and `method` options.
- `ctx_key` and `method` options are controversial, so you can use only one of them.
- with `ctx_key` you can specify the key inside action context with value for `octo`
- with `method` you can specify method name symbol, which will be called to retrieve `octo` value, like we do for `if` and `unless` options.
```ruby
logic do
palp :palp_name_one do
Expand Down Expand Up @@ -263,7 +267,60 @@ Currently only one possibility is present to define flow for `octo`, it's `palp`
***
## Options

### ctx_key: context key with octo value

See examples above

***

### method: method symbol which returns octo value
<details><summary><b>EXAMPLE (CLICK ME)</b></summary>
<p>

```ruby
require 'decouplio'

class SomeAction < Decouplio::Action
logic do
palp :palp_one do
step :step_one
end

palp :palp_two do
step :step_two
end

octo :octo_name, method: :what_is_next? do
on :option_one, palp: :palp_one
on :option_two, palp: :palp_two
end
end

def step_one(**)
# ...
end

def step_two(**)
# ...
end

def what_is_next?(connection:, url:)
connection.get(url).body[:decision]
end
end
```

</p>
</details>

***

### if: condition method name
The same as for [step](https://github.com/differencialx/decouplio/blob/master/docs/step.md)

***

### unless: condition method name
The same as for [step](https://github.com/differencialx/decouplio/blob/master/docs/step.md)

***
2 changes: 1 addition & 1 deletion docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ Learn more about all features:
- [Wrap](https://github.com/differencialx/decouplio/blob/master/docs/wrap.md)
- [Resq](https://github.com/differencialx/decouplio/blob/master/docs/resq.md)
- [Inner action](https://github.com/differencialx/decouplio/blob/master/docs/inner_action.md)
- [Doby](https://github.com/differencialx/decouplio/blob/master/docs/doby.md)
- [Doby/Aide](https://github.com/differencialx/decouplio/blob/master/docs/doby_aide.md)
- [Step as a service](https://github.com/differencialx/decouplio/blob/master/docs/step_as_a_service.md)
- [Error store](https://github.com/differencialx/decouplio/blob/master/docs/error_store.md)
Loading

0 comments on commit 06d2ffd

Please sign in to comment.