trailblazer-developer 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41c30437086de2bc9a0148eccf3db59603e484f92c032ff923cd0275fd369db0
4
- data.tar.gz: bd45234bd028d5a5ef5348959da4b834ffdc6bf79af3821689718d76055ef4df
3
+ metadata.gz: c162908350116143c05730ff70ef9336d826214f9a3fca7d159e5487ad4814a3
4
+ data.tar.gz: 07dc4b9adccc4a6b302f4b1382791a1b7001244b4ecb6e600dd6e67986eb13be
5
5
  SHA512:
6
- metadata.gz: a66246114d6111e30c76993e18308675544b7623a8afcf732c9e0feab79cdda46dbcc3f789c20ea990c2276f1ef48321802b8f59c40706beab6480aa587bee80
7
- data.tar.gz: 4bfdbbb63921aadf36c77c4c96a2da0e2efc0d283140b0263c504743bca92fbbc26a6f31ad7910bae09654e80a58c8d1deb53513fb1866c9e49bb060cc5ad313
6
+ metadata.gz: 45b8781d48450057467840d4742c9499b7d75bc26cb7ec7afda25ea6b57adfdae01ee93383ac2680203b50f33242c725d298f639f7aac342b018c4364054ba03
7
+ data.tar.gz: 0343ef1ffdc8b5cdda41991112f968e45b80e25b5fdd30c47ffa259296b4ca56eed7209f05697fa16d91a91286c2f39d0b6ade72122d00b0b3799ac1cd0f668e
data/.gitignore CHANGED
@@ -1,9 +1,14 @@
1
+ .idea
2
+ .rakeTasks
3
+ .tool-versions
1
4
  /.bundle/
2
5
  /.yardoc
3
6
  /Gemfile.lock
7
+ /gems.local.rb.lock
4
8
  /_yardoc/
5
9
  /coverage/
6
10
  /doc/
7
11
  /pkg/
8
12
  /spec/reports/
9
13
  /tmp/
14
+ .rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ inherit_from:
2
2
  - https://raw.githubusercontent.com/trailblazer/meta/master/rubocop.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.1
5
+ TargetRubyVersion: 2.5
6
6
  Exclude:
7
7
  - 'test/hash/bla.rb'
8
8
 
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.3.1
5
- before_install:
6
- - gem install bundler
3
+ - 2.6.2
4
+ - 2.5.5
5
+ - 2.4.4
6
+
7
+ cache: bundler
data/Gemfile CHANGED
@@ -4,9 +4,8 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  # gem "trailblazer-activity", ">= 0.7.1"
7
- gem "trailblazer-activity", path: "../trailblazer-activity"
8
- gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
9
-
10
- # gem "json"
7
+ # gem "trailblazer-activity", path: "../trailblazer-activity"
8
+ # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
9
+ # gem "trailblazer-activity-dsl-linear", github: "trailblazer/trailblazer-activity-dsl-linear"
11
10
 
12
11
  gem "representable"
data/Rakefile CHANGED
@@ -11,4 +11,4 @@ end
11
11
  RuboCop::RakeTask.new(:rubocop)
12
12
 
13
13
  desc "Running Tests"
14
- task default: %i[test rubocop]
14
+ task default: %i[test]
data/gems.local.rb ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in trailblazer-developer.gemspec
4
+ gemspec
5
+
6
+ gem "trailblazer-activity", path: "../trailblazer-activity"
7
+ gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
8
+ gem "representable"
@@ -0,0 +1,7 @@
1
+ # 0.0.2
2
+
3
+ * Add `Developer.render` shortcut to `Render::Circuit`.
4
+
5
+ # 0.0.1
6
+
7
+ * Initial release into an unsuspecting world.
@@ -7,7 +7,7 @@ module Trailblazer
7
7
  module_function
8
8
 
9
9
  Element = Struct.new(:id, :type, :linksTo, :data, :label)
10
- Arrow = Struct.new(:target, :label)
10
+ Arrow = Struct.new(:target, :label, :message)
11
11
 
12
12
  module Representer
13
13
  class Activity < Representable::Decorator
@@ -19,18 +19,33 @@ module Trailblazer
19
19
  collection :linksTo, class: Arrow, default: [] do
20
20
  property :target
21
21
  property :label
22
+ property :message
22
23
  end
23
24
  property :data, default: {}
25
+
24
26
  property :label
25
27
  end
26
28
  end
27
29
  end
28
30
 
29
31
  def call(hash)
30
- elements = Representer::Activity.new(OpenStruct.new).from_hash(hash).elements
32
+ elements = transform_from_hash(hash)
33
+ elements = remap_ids(elements)
34
+
35
+ compute_intermediate(elements)
36
+ end
37
+
38
+ def transform_from_hash(hash)
39
+ Representer::Activity.new(OpenStruct.new).from_hash(hash).elements
40
+ end
41
+
42
+ def find_start_events(elements)
43
+ elements.find_all { |el| el.type == "Event" }
44
+ end
31
45
 
32
- start_events = elements.find_all { |el| el.type == "Event" }
33
- end_events = elements.find_all { |el| el.type == "EndEventTerminate" }# DISCUSS: TERMINATE?
46
+ def compute_intermediate(elements, find_start_events: method(:find_start_events))
47
+ start_events = find_start_events.(elements)
48
+ end_events = elements.find_all { |el| el.type == "EndEventTerminate" } # DISCUSS: is it really called TERMINATE?
34
49
 
35
50
  inter = Activity::Schema::Intermediate
36
51
 
@@ -38,11 +53,12 @@ module Trailblazer
38
53
  wiring = Hash[wiring]
39
54
 
40
55
  # end events need this stupid special handling
56
+ # DISCUSS: currently, the END-SEMANTIC is read from the event's label.
41
57
  wiring = wiring.merge(Hash[
42
58
  end_events.collect do |_end|
43
59
  ref, outputs = wiring.find { |ref, _| ref.id == _end.id }
44
60
 
45
- [ref, [inter.Out(semantic_for(_end.to_h), nil)]]
61
+ [ref, [inter.Out(semantic_for(_end.to_h)|| raise, nil)]] # TODO: test the raise, happens when the semantic of an End can't be distinguished. # TODO: don't extract semantic from :label but from :data.
46
62
  end
47
63
  ])
48
64
  # pp wiring
@@ -52,14 +68,51 @@ module Trailblazer
52
68
 
53
69
  # private
54
70
 
71
+
72
+
55
73
  # We currently use the {:label} field of an arrow to encode an output semantic.
56
74
  # The {:symbol_style} part will be filtered out as semantic. Defaults to {:success}.
57
75
  def semantic_for(label:nil, **)
58
76
  return :success unless label
59
77
 
60
- m = label.match(/:(\w+)/)
78
+ extract_semantic(label)
79
+ end
80
+
81
+ def extract_semantic(label)
82
+ m = label.match(/:([^\s][\w\?!]+)/) or return
83
+ return m[1].to_sym
84
+ end
85
+
86
+ def extract_string_id(label)
87
+ m = label.match(/"(.+)"/) or return
61
88
  return m[1].to_sym
62
89
  end
90
+
91
+ def extract_id(label)
92
+ extract_string_id(label) || extract_semantic(label)
93
+ end
94
+
95
+ # remap {id}
96
+ def remap_ids(elements)
97
+ map = {}
98
+
99
+ elements.collect do |el|
100
+ id = (el.label && semantic = extract_id(el.label)) ? semantic : el.id.to_sym
101
+
102
+ map[el.id] = id
103
+
104
+ el.id = id
105
+ end
106
+
107
+ # remap {linksTo}
108
+ elements.collect do |el|
109
+ el.linksTo.collect do |link|
110
+ link.target = map[link.target]
111
+ end
112
+ end
113
+
114
+ elements
115
+ end
63
116
  end
64
117
  end
65
118
  end
@@ -1,5 +1,11 @@
1
1
  module Trailblazer
2
2
  module Developer
3
+ module_function
4
+
5
+ def render(activity)
6
+ Render::Circuit.(activity)
7
+ end
8
+
3
9
  module Render
4
10
  module Circuit
5
11
  module_function
@@ -1,5 +1,7 @@
1
1
  module Trailblazer
2
- module Developer
3
- VERSION = "0.0.1".freeze
2
+ module Version
3
+ module Developer
4
+ VERSION = "0.0.2".freeze
5
+ end
4
6
  end
5
7
  end
@@ -1,17 +1,20 @@
1
1
  module Trailblazer::Developer
2
2
  module_function
3
3
 
4
- def wtf(activity, args)
5
- Wtf.invoke(activity, args)
4
+ def wtf(activity, *args)
5
+ Wtf.invoke(activity, *args)
6
+ end
7
+
8
+ class << self
9
+ alias wtf? wtf
6
10
  end
7
- alias_method :wtf?, :wtf
8
11
 
9
12
  module Wtf
10
13
  module_function
11
14
 
12
15
  # Run {activity} with tracing enabled and inject a mutable {Stack} instance.
13
16
  # This allows to display the trace even when an exception happened
14
- def invoke(activity, (ctx, flow_options))
17
+ def invoke(activity, (ctx, flow_options), *args)
15
18
  flow_options ||= {} # Ruby sucks.
16
19
 
17
20
  # this instance gets mutated with every step. unfortunately, there is
@@ -19,14 +22,14 @@ module Trailblazer::Developer
19
22
  stack = Trailblazer::Activity::Trace::Stack.new
20
23
 
21
24
  begin
22
- returned_stack, _ = Trailblazer::Activity::Trace.invoke( activity,
25
+ _returned_stack, *returned = Trailblazer::Activity::Trace.invoke( activity,
23
26
  [
24
27
  ctx,
25
28
  flow_options.merge(stack: stack)
26
- ]
29
+ ],
30
+ *args
27
31
  )
28
32
  rescue
29
-
30
33
  # DISCUSS: we shouldn't use internal knowledge of the Stack/Level API here.
31
34
  closest = stack.to_a
32
35
  while closest.is_a?(Trailblazer::Activity::Trace::Level) && closest = closest.last do # FIXME: deep-dive via Stack API.
@@ -36,6 +39,8 @@ module Trailblazer::Developer
36
39
 
37
40
  handle(stack, $!, closest.task, activity, [ctx, flow_options])
38
41
  end
42
+
43
+ returned # FIXME: test me
39
44
  end
40
45
 
41
46
  def exception_renderer(stack:, level:, input:, name:, closest_task:)
@@ -6,6 +6,7 @@ module Trailblazer
6
6
  end
7
7
  end
8
8
 
9
+ require "trailblazer/developer/wtf"
9
10
  require "trailblazer/developer/generate"
10
11
  require "trailblazer/developer/render/circuit"
11
12
 
@@ -4,7 +4,7 @@ require "trailblazer/developer/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "trailblazer-developer"
7
- spec.version = Trailblazer::Developer::VERSION
7
+ spec.version = Trailblazer::Version::Developer::VERSION
8
8
  spec.authors = ["Nick Sutterer"]
9
9
  spec.email = ["apotonick@gmail.com"]
10
10
 
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rubocop"
24
24
 
25
25
  spec.add_dependency "trailblazer-activity", "~> 0.8"
26
+ spec.add_dependency "trailblazer-activity-dsl-linear"
26
27
  spec.add_dependency "representable"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-developer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: trailblazer-activity-dsl-linear
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: representable
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -102,7 +116,6 @@ extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
118
  - ".gitignore"
105
- - ".rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml"
106
119
  - ".rubocop.yml"
107
120
  - ".travis.yml"
108
121
  - Gemfile
@@ -110,7 +123,9 @@ files:
110
123
  - Rakefile
111
124
  - bin/console
112
125
  - bin/setup
126
+ - gems.local.rb
113
127
  - lib/trailblazer/developer.rb
128
+ - lib/trailblazer/developer/CHANGES.md
114
129
  - lib/trailblazer/developer/activity.rb
115
130
  - lib/trailblazer/developer/client.rb
116
131
  - lib/trailblazer/developer/generate.rb
@@ -1,115 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.5.0
3
- DisplayCopNames: true
4
- Layout/CaseIndentation:
5
- IndentOneStep: true
6
- Layout/FirstArrayElementLineBreak:
7
- Enabled: true
8
- Layout/FirstHashElementLineBreak:
9
- Enabled: true
10
- Layout/FirstMethodArgumentLineBreak:
11
- Enabled: true
12
- Layout/FirstMethodParameterLineBreak:
13
- Enabled: true
14
- Layout/MultilineAssignmentLayout:
15
- Enabled: true
16
- EnforcedStyle: same_line
17
- Layout/SpaceInsideHashLiteralBraces:
18
- EnforcedStyle: no_space
19
- Metrics/LineLength:
20
- Max: 130
21
- Metrics/ParameterLists:
22
- Max: 5
23
- Naming/VariableNumber:
24
- EnforcedStyle: snake_case
25
- Style/AndOr:
26
- EnforcedStyle: conditionals
27
- Style/AutoResourceCleanup:
28
- Enabled: true
29
- Style/CollectionMethods:
30
- Enabled: true
31
- Style/Documentation:
32
- Enabled: false
33
- Style/EmptyLiteral:
34
- Enabled: false
35
- Style/EmptyMethod:
36
- EnforcedStyle: expanded
37
- Style/FormatStringToken:
38
- EnforcedStyle: template
39
- Style/ImplicitRuntimeError:
40
- Enabled: true
41
- Style/MethodCalledOnDoEndBlock:
42
- Enabled: true
43
- Style/MethodDefParentheses:
44
- EnforcedStyle: require_parentheses
45
- Style/MissingElse:
46
- Enabled: true
47
- EnforcedStyle: case
48
- Style/NumericLiterals:
49
- Enabled: false
50
- Style/OptionHash:
51
- Enabled: true
52
- Style/PercentLiteralDelimiters:
53
- PreferredDelimiters:
54
- "%w": "[]"
55
- "%W": "[]"
56
- "%i": "[]"
57
- "%I": "[]"
58
- "%r": "()"
59
- Style/ReturnNil:
60
- Enabled: true
61
- Style/SafeNavigation:
62
- Enabled: false
63
- Style/Send:
64
- Enabled: true
65
- Style/SignalException:
66
- EnforcedStyle: semantic
67
- Style/StringLiterals:
68
- EnforcedStyle: double_quotes
69
- Style/StringLiteralsInInterpolation:
70
- EnforcedStyle: double_quotes
71
- Style/StringMethods:
72
- Enabled: true
73
- Style/SymbolArray:
74
- Enabled: true
75
- # this allows in rspec to have expect { } with multiple lines
76
- Style/BlockDelimiters:
77
- EnforcedStyle: braces_for_chaining
78
- Layout/EndOfLine:
79
- Enabled: false
80
- # don't need these checks in test folders
81
- Metrics/ModuleLength:
82
- Exclude:
83
- - "spec/**/*"
84
- - "test/**/*"
85
- Metrics/BlockLength:
86
- Exclude:
87
- - "spec/**/*"
88
- - "test/**/*"
89
- - "*.gemspec" # definitely not in the gemspec
90
- Metrics/MethodLength:
91
- Max: 20
92
- Lint/UnreachableCode:
93
- Description: 'Unreachable code.'
94
- Enabled: false
95
- Lint/Void:
96
- Enabled: false
97
- Layout/AlignHash:
98
- EnforcedLastArgumentHashStyle: ignore_implicit
99
- Metrics/AbcSize:
100
- Max: 25
101
- Style/LambdaCall:
102
- Enabled: false
103
- Style/Semicolon:
104
- Enabled: false
105
- Naming/UncommunicativeMethodParamName:
106
- Enabled: false
107
- Style/ClassAndModuleChildren:
108
- Enabled: false
109
- Layout/LeadingCommentSpace:
110
- Exclude:
111
- - 'test/docs/**/*'
112
- Layout/AlignHash:
113
- EnforcedHashRocketStyle: table
114
- Style/FrozenStringLiteralComment:
115
- Enabled: false