caixanegra 0.1.0 → 0.1.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
  SHA256:
3
- metadata.gz: fd21dec4c184b88b2898d5f011eb9e7288562c28f2204db0a6e85cca004153de
4
- data.tar.gz: 49b39b216ac37609aa921ece85a263de64a7e932082d80761388e41d5c5eaf3d
3
+ metadata.gz: df3d38ccee4981c27d6acb8e72bc4c40c00537c6c370cdc17581de1dc179ac3f
4
+ data.tar.gz: 4bad76dfbfb9834d19389a28f92a7b3a7a1208c9cdf230a43fc4f9faf6322fb4
5
5
  SHA512:
6
- metadata.gz: 8dcad855ae35dc5241379f3f4acc574ec4b0204877cea2d8770a08cf9774ffe7257f0a873ac0e067048ea432ee4c2689c94afea393aecd94942764b42ea67e06
7
- data.tar.gz: a636a4d03ab305b54464f2003488fdb21f756f3876f4899da6b026b53e6f3326a4909a860ec7cb3390eecb68530e9070c44ed794a9fa484fbf25dbd35411d424
6
+ metadata.gz: 464c5ebbc06fa24c1f6f9261dd9e4241dff7bbfc8ccca0f067de5f289e5bda3a4e658475c8b15fa72971574748927016e5e23eed6020a0eda94580e7e85128ed
7
+ data.tar.gz: 55fcf0df7d3aac4d6e4458728cab6f3cfe874014903d47b5e4de1976290d8728cccdd28a687a748e43b5338bb6090b94596bb56fb43437ebbf203934c525717a
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2021 sergiorribeiro
1
+ Copyright 2023 sergiorribeiro
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,18 +1,69 @@
1
1
  # caixanegra
2
2
  ![Gem](https://img.shields.io/gem/v/caixanegra?logo=ruby&logoColor=red)
3
3
 
4
- ## Getting Started
4
+ An unopinionated flow oriented blackbox designer, executor and debugger to interface your service classes and allow users to manipulate or completely redesign processes using your code.
5
5
 
6
+ # Installation
7
+ Add this line to your application's Gemfile:
6
8
 
9
+ ```ruby
10
+ gem 'caixanegra'
11
+ ```
7
12
 
13
+ or
8
14
 
15
+ ```
16
+ bundler add caixanegra
17
+ ```
18
+ # Getting Started
19
+ **caixanegra** implements a self-contained designer, which only requires Redis to be able to receive and report back flow descriptors.
20
+ To get started, the only thing you need is to point to your Redis instance and point which classes on your codebase should represent units.
9
21
 
22
+ First, mount the engine. Add the line below to `routes.rb` file:
10
23
 
11
- ## Installation
12
- Add this line to your application's Gemfile:
24
+ ```ruby
25
+ mount Caixanegra::Engine, at: "/caixanegra", as: :caixanegra
26
+ ```
27
+
28
+ Then, let's create a `caixanegra.rb` initializer (or any name you prefer)
13
29
 
14
30
  ```ruby
15
- gem 'caixanegra'
31
+ Caixanegra.setup do |config|
32
+ config.units = {
33
+ awesome_unit: Caixanegra::Units::AU,
34
+ another_awesome_unit: Some::Other::Namespace::AAU,
35
+ you_can_also: {
36
+ scope_units: Caixanegra::Units::ScopedUnit,
37
+ },
38
+ }
39
+ config.redis = Redis.new
40
+ end
41
+ ```
42
+
43
+ With the designer configured, you can use `Caixanegra::Manager` to handle the previously stored definition (or an empty one).
44
+ This will give you the UID that **caixanegra** designer will understand.
45
+
46
+ ```ruby
47
+ my_flow = somewhere.get_flow # get from your own persistence or transport solution
48
+ uid = Caixanegra::Manager.handler(my_flow || {})
16
49
  ```
17
- ## License
50
+
51
+ You can then safely navigate to the designer.
52
+
53
+ ```ruby
54
+ link_to "Some flow", "/caixanegra/design/#{@uid}?unit_scope=optional_scope,another_optional_scope", target: :_blank
55
+ ```
56
+
57
+ Saved changes will update the flow definition on Redis, and you must then persist them. You can get the flow definition for any specified **caixanegra** handled UID:
58
+
59
+ ```ruby
60
+ updated_flow = Caixanegra::Manager.get(my_uid)
61
+ persist_flow(updated_flow) # your own persistence or transport solution. It's a JSON
62
+ ```
63
+
64
+ **NOTE:** There's currently no managed way to set callbacks on save actions from the designer. Working on it
65
+
66
+ Please, refer to [the wiki](https://github.com/sergiorribeiro/caixanegra/wiki) to get to know more about [units](https://github.com/sergiorribeiro/caixanegra/wiki/Anatomy-of-a-unit).
67
+
68
+ # License
18
69
  **caixanegra** is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -166,9 +166,9 @@ window.Caixanegra.Designer = {
166
166
  ctx.beginPath();
167
167
  ctx.moveTo(this.#drawValues.position.x + this.size.x, exit.markerY);
168
168
  ctx.lineTo(this.#drawValues.position.x + this.size.x + 25, exit.markerY);
169
-
169
+
170
170
  if (this.connectingExit === exit && context.mouse.move) {
171
- ctx.lineTo(context.mouse.move.x, context.mouse.move.y);
171
+ ctx.lineTo(context.mouse.move.x + context.referential.x, context.mouse.move.y + context.referential.y);
172
172
  } else if (exit.reference.target) {
173
173
  const targetCenter = exit.reference.target.getCenter(context.referential);
174
174
  ctx.lineTo(targetCenter.x, targetCenter.y);
@@ -382,10 +382,10 @@ window.Caixanegra.Designer = {
382
382
  }
383
383
 
384
384
  deleteUnit() {
385
- this.removeUnit(this.selectedUnit.oid);
386
- this.toggleDeleteConfirmation();
387
385
  this.unitDetailPane.classList.remove("-open");
388
386
  this.unitDebugHitsPane.classList.remove("-open");
387
+ this.removeUnit(this.selectedUnit.oid);
388
+ this.toggleDeleteConfirmation();
389
389
  }
390
390
 
391
391
  flushToConsole(entries) {
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caixanegra
4
- module API
4
+ module Api
5
5
  module Designer
6
- class FlowsController < ::Caixanegra::APIController
6
+ class FlowsController < ::Caixanegra::ApiController
7
7
  before_action :set_flow, only: %i[show debug_run]
8
8
 
9
9
  def show
@@ -20,7 +20,6 @@ module Caixanegra
20
20
  execution = Caixanegra::Executor.new(
21
21
  initial_carryover: initial_carryover,
22
22
  flow_definition: @flow,
23
- unit_scope: params[:unit_scope],
24
23
  debug_mode: true
25
24
  ).run
26
25
 
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caixanegra
4
- module API
4
+ module Api
5
5
  module Designer
6
- class UnitsController < ::Caixanegra::APIController
6
+ class UnitsController < ::Caixanegra::ApiController
7
7
  def index
8
8
  render json: units
9
9
  end
@@ -15,26 +15,20 @@ module Caixanegra
15
15
  end
16
16
 
17
17
  def units
18
- @units ||= begin
19
- base_units = Caixanegra.units.reject { |_, v| v.is_a? Hash }
20
- scope_units = Caixanegra.units[unit_scope] if unit_scope.present?
21
- all_units = base_units.merge(scope_units || {})
18
+ @units ||= ::Caixanegra::UnitHelper.scoped_units(unit_scope).map do |k, v|
19
+ base = {
20
+ title: v.name,
21
+ type: v.type,
22
+ description: v.description,
23
+ class: k,
24
+ exits: v.exits&.map { |e| { name: e } },
25
+ inputs: v.inputs,
26
+ assignments: v.assignments
27
+ }
22
28
 
23
- all_units.map do |k, v|
24
- base = {
25
- title: v.name,
26
- type: v.type,
27
- description: v.description,
28
- class: k,
29
- exits: v.exits&.map { |e| { name: e } },
30
- inputs: v.inputs,
31
- assignments: v.assignments
32
- }
29
+ base[:set] = v.set if base[:set]
33
30
 
34
- base[:set] = v.set if base[:set]
35
-
36
- base
37
- end
31
+ base
38
32
  end
39
33
  end
40
34
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caixanegra
4
- class APIController < ActionController::API
4
+ class ApiController < ActionController::API
5
5
  end
6
6
  end
@@ -36,6 +36,12 @@ module Caixanegra
36
36
  }
37
37
  end
38
38
 
39
+ def exit_and_return
40
+ {
41
+ carry_over: @carry_over
42
+ }
43
+ end
44
+
39
45
  def flow
40
46
  exit_through exits.first
41
47
  end
@@ -64,7 +70,10 @@ module Caixanegra
64
70
 
65
71
  input_value = result
66
72
  end
73
+
67
74
  input_value.presence || @inputs[id][:default]
75
+ rescue StandardError
76
+ raise(UnitIOException.new, "Unable to fetch input '#{id}'")
68
77
  end
69
78
 
70
79
  def name
@@ -6,13 +6,13 @@ module Caixanegra
6
6
  self.units = []
7
7
 
8
8
  def self.setup(&block)
9
- yield self
9
+ yield self
10
10
  end
11
11
 
12
12
  class Engine < ::Rails::Engine
13
13
  isolate_namespace Caixanegra
14
14
 
15
- initializer "caixanegra.assets.precompile" do |app|
15
+ initializer 'caixanegra.assets.precompile' do |app|
16
16
  app.config.assets.precompile += %w[
17
17
  caixanegra/api.js
18
18
  caixanegra/caixanegra.js
@@ -2,4 +2,6 @@
2
2
 
3
3
  module Caixanegra
4
4
  class UnitScopedException < StandardError; end
5
+ class UnitIOException < StandardError; end
6
+ class ContinuityException < StandardError; end
5
7
  end
@@ -5,7 +5,6 @@ module Caixanegra
5
5
  def initialize(params)
6
6
  @initial_carryover = params[:initial_carryover] || {}
7
7
  @flow = (params[:flow_definition] || {}).deep_symbolize_keys
8
- @unit_scope = params[:unit_scope]
9
8
  @debug_mode = params[:debug_mode] == true
10
9
  @execution = { history: [], steps: [] }
11
10
  @storage = {}
@@ -27,7 +26,7 @@ module Caixanegra
27
26
  end
28
27
 
29
28
  def run_and_report_result
30
- log_console_entry "Started"
29
+ log_console_entry 'Started'
31
30
  set_start_unit
32
31
  format_result(flow_through)
33
32
  rescue Caixanegra::UnitScopedException => e
@@ -113,6 +112,8 @@ module Caixanegra
113
112
  raise exception
114
113
  end
115
114
  next_unit = next_unit(result)
115
+ raise(ContinuityException.new, "Unable to choose a valid exit") if next_unit.nil?
116
+
116
117
  log_step_result(result, next_unit)
117
118
  @execution[:steps] += feeder_steps
118
119
  @step_unit = next_unit
@@ -143,6 +144,8 @@ module Caixanegra
143
144
  end
144
145
 
145
146
  def next_unit(result)
147
+ return nil if result.nil?
148
+
146
149
  exit_name = result[:exit_through]
147
150
  metadata = unit_metadata(@step_unit.oid)
148
151
  log_console_entry "Next unit found through '#{exit_name}': '#{@step_unit.oid}'"
@@ -187,15 +190,13 @@ module Caixanegra
187
190
  unit_class = scoped_units[unit_data[:class].to_sym]
188
191
  inputs = unit_class.inputs
189
192
  unit_class.new(unit_data[:oid], inputs, mappings, carry_over, @storage)
193
+ rescue
194
+ log_console_entry "Unable to load unit instance of type '#{unit_data[:class]}'"
195
+ nil
190
196
  end
191
197
 
192
198
  def scoped_units
193
- @scoped_units ||= begin
194
- base_units = Caixanegra.units.reject { |_, v| v.is_a? Hash }
195
- scope_units = Caixanegra.units[@unit_scope] if @unit_scope.present?
196
-
197
- base_units.merge(scope_units || {})
198
- end
199
+ @scoped_units ||= UnitHelper.all_units
199
200
  end
200
201
  end
201
202
  end
@@ -4,7 +4,7 @@ module Caixanegra
4
4
  class Manager
5
5
  class << self
6
6
  def handler(flow_definition = {})
7
- uid = SecureRandom.uuid.gsub("-", "")
7
+ uid = SecureRandom.uuid.gsub('-', '')
8
8
 
9
9
  Caixanegra.redis.multi do |pipeline|
10
10
  pipeline.hset(:caixanegra, uid, JSON.dump(flow_definition))
@@ -0,0 +1,32 @@
1
+ module Caixanegra
2
+ class UnitHelper
3
+ class << self
4
+ def scoped_units(scope)
5
+ all_units = {}
6
+ all_units = all_units.merge(Caixanegra.units.reject { |_, v| v.is_a? Hash })
7
+
8
+ (scope || "").split(",").each do |current_scope|
9
+ all_units = all_units.merge(Caixanegra.units[current_scope.to_sym])
10
+ end
11
+
12
+ all_units
13
+ end
14
+
15
+ def all_units
16
+ all_units = {}
17
+
18
+ Caixanegra.units.each do |k, v|
19
+ if v.is_a? Hash
20
+ v.each do |ik, iv|
21
+ all_units[ik] = iv
22
+ end
23
+ else
24
+ all_units[k] = v
25
+ end
26
+ end
27
+
28
+ all_units
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Caixanegra
2
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
3
5
  end
data/lib/caixanegra.rb CHANGED
@@ -1,8 +1,10 @@
1
- require "caixanegra/exceptions"
2
- require "caixanegra/engine"
3
- require "caixanegra/version"
4
- require "caixanegra/executor"
5
- require "caixanegra/manager"
1
+ # frozen_string_literal: true
6
2
 
7
- module Caixanegra
8
- end
3
+ require 'caixanegra/exceptions'
4
+ require 'caixanegra/unit_helper'
5
+ require 'caixanegra/engine'
6
+ require 'caixanegra/version'
7
+ require 'caixanegra/executor'
8
+ require 'caixanegra/manager'
9
+
10
+ module Caixanegra ; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caixanegra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergiorribeiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2023-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,7 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: TBD
41
+ description: An unopinionated, flow oriented blackbox designer and executor to interface
42
+ your service classes
42
43
  email:
43
44
  - sergio.r.ribeiro@live.com
44
45
  executables: []
@@ -71,13 +72,13 @@ files:
71
72
  - lib/caixanegra/exceptions.rb
72
73
  - lib/caixanegra/executor.rb
73
74
  - lib/caixanegra/manager.rb
75
+ - lib/caixanegra/unit_helper.rb
74
76
  - lib/caixanegra/version.rb
75
77
  - lib/tasks/caixanegra_tasks.rake
76
- homepage: http://sergioribeiro.com
78
+ homepage: https://github.com/sergiorribeiro/caixanegra/wiki
77
79
  licenses:
78
80
  - MIT
79
- metadata:
80
- allowed_push_host: https://rubygems.org
81
+ metadata: {}
81
82
  post_install_message:
82
83
  rdoc_options: []
83
84
  require_paths:
@@ -86,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
87
  requirements:
87
88
  - - ">="
88
89
  - !ruby/object:Gem::Version
89
- version: '0'
90
+ version: 2.7.5
90
91
  required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  requirements:
92
93
  - - ">="
@@ -96,5 +97,5 @@ requirements: []
96
97
  rubygems_version: 3.3.17
97
98
  signing_key:
98
99
  specification_version: 4
99
- summary: TBD
100
+ summary: Unopinionated flow oriented blackbox designer, executor and debugger
100
101
  test_files: []