Skip to content

Commit

Permalink
support ruby 2.7 (#24)
Browse files Browse the repository at this point in the history
* support ruby 2.7

* test in ruby 2.7
  • Loading branch information
seuros authored Jan 17, 2021
1 parent 6481175 commit d3336f8
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 30 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: ruby
before_install: gem install bundler
cache: bundler
rvm:
- 2.7
- 2.6
- 2.5
- 2.4

cache: bundler
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ gemspec
# gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
# gem "trailblazer-activity-dsl-linear", github: "trailblazer/trailblazer-activity-dsl-linear"

gem "representable"
gem "faraday"
gem "multi_json"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018 Trailblazer GmbH
Copyright (c) 2018-2020 Trailblazer GmbH

Trailblazer is an Open Source project licensed under the terms of
the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
Expand Down
3 changes: 3 additions & 0 deletions gems.local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
gem "trailblazer-activity", path: "../trailblazer-activity"
gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
gem "representable"
gem 'pry-byebug'
gem "faraday"
gem "multi_json"
2 changes: 1 addition & 1 deletion lib/trailblazer/developer/render/circuit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def circuit_hash(graph, **options)

content = content.join("\n")

return "\n#{content}".gsub(/0x\w+/, "0x")#.gsub(/0.\d+/, "0.")
"\n#{content}".gsub(/0x\w+/, "0x")
end

# If Ruby had pattern matching, this function wasn't necessary.
Expand Down
6 changes: 4 additions & 2 deletions lib/trailblazer/developer/trace/present.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def call(stack, level: 1, tree: [], renderer: method(:default_renderer), **optio
end

def tree(stack, level, tree:, renderer:, **options)
tree_for(stack, level, **options.merge(tree: tree))
opts = options.merge(tree: tree)
tree_for(stack, level, **opts)

nodes = tree.each_with_index.map do |task_node, position|
renderer.(task_node: task_node, position: position, tree: tree)
Expand All @@ -30,7 +31,8 @@ def tree_for(stack, level, tree:, **options)
tree.push(*TreeNodes.for(level, options.merge(input: input, output: output)))

if nested.any? # nesting
tree_for(nested, level + 1, **options.merge(tree: tree))
opts = options.merge(tree: tree)
tree_for(nested, level + 1, **opts)
end

tree
Expand Down
11 changes: 6 additions & 5 deletions lib/trailblazer/developer/wtf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def arguments_for_trace(activity, (ctx, original_flow_options), **circuit_option
variables: Array( flow_options.dig(:focus_on, :variables) ),
}

return activity, [ ctx, flow_options ], circuit_options
[activity, [ ctx, flow_options ], circuit_options]
end

# Overring default input and output data collectors to collect/capture
Expand All @@ -61,7 +61,7 @@ def arguments_for_trace(activity, (ctx, original_flow_options), **circuit_option
def trace_input_data_collector(wrap_config, (ctx, flow_options), circuit_options)
data = Trace.default_input_data_collector(wrap_config, [ctx, flow_options], circuit_options)

if Wtf.caputure_variables?(step_name: data[:task_name], **flow_options)
if Wtf.capture_variables?(step_name: data[:task_name], **flow_options)
data[:focused_variables] = Trace::Focusable.capture_variables_from(ctx, **flow_options)
end

Expand All @@ -72,18 +72,19 @@ def trace_output_data_collector(wrap_config, (ctx, flow_options), circuit_option
data = Trace.default_output_data_collector(wrap_config, [ctx, flow_options], circuit_options)
input = flow_options[:stack].top

if Wtf.caputure_variables?(step_name: input.data[:task_name], **flow_options)
if Wtf.capture_variables?(step_name: input.data[:task_name], **flow_options)
data[:focused_variables] = Trace::Focusable.capture_variables_from(ctx, **flow_options)
end

data
end

# private
def caputure_variables?(step_name:, focus_on:, **)
def capture_variables?(step_name:, focus_on:, **)
return true if focus_on[:steps].include?(step_name) # For given step
return true if focus_on[:steps].empty? && focus_on[:variables].any? # For selected vars but all steps
return false

false
end
end
end
3 changes: 3 additions & 0 deletions lib/trailblazer/developer/wtf/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def value_for(tree, task_node, position)
end

def fmt(line, style)
if line.is_a? Method
line = "#<Method: #<Class:>.#{line.name}>"
end
return line unless style
String.send(style, line)
end
Expand Down
12 changes: 7 additions & 5 deletions test/docs/developer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ def a(ctx, **)
end
end

assert_raises TypeError do
#:type-err
ctx = {"message" => "Not gonna work!"} # bare hash.
Bla.([ctx])
#:type-err end
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
assert_raises TypeError do
#:type-err
ctx = {"message" => "Not gonna work!"} # bare hash.
Bla.([ctx])
#:type-err end
end
end

=begin
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "trailblazer/activity"
require "trailblazer/activity/testing"
require "trailblazer/activity/dsl/linear"
puts "Running in Ruby #{RUBY_VERSION}"

T = Trailblazer::Activity::Testing

Expand Down
20 changes: 9 additions & 11 deletions test/trace/wtf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def <<(value)
}
end


it "traces until charlie, 3-level and step takes left track" do
output, _ = capture_io do
Trailblazer::Developer.wtf?(alpha, [{ seq: [], c: false }])
Expand All @@ -78,7 +77,6 @@ def <<(value)
}
end


it "traces alpha and it's subprocesses, for successful execution" do
output, _ = capture_io do
Trailblazer::Developer.wtf?(alpha, [{ seq: [] }])
Expand Down Expand Up @@ -135,24 +133,24 @@ def <<(value)
{ seq: [], message: 'WTF!' },
{ focus_on: { steps: alpha.method(:a) } }
],
)

)
nested = flow_options[:stack].to_a.last

tasks = nested.select{ |e| e.is_a?(Dev::Trace::Level) } # exclude ends

# Trace::Entity::Input & Trace::Entity::Output for
# task `:a` must contain {focused_variables} and not others
tasks.each do |(input, *remainings)|
if input.task.inspect.gsub(/0x\w+/, "").include?('#<Method: #<Class:>.a>>')
_(input.data.keys).must_include(:focused_variables)
if %r{(Method: \#<Class:)(.*)\#a\(|\.a>}.match(input.task.inspect)
assert_includes input.data.keys, :focused_variables, input.task.inspect
else
_(input.data.keys).wont_include(:focused_variables)
end

output = remainings.last

if output.task.inspect.gsub(/0x\w+/, "").include?('#<Method: #<Class:>.a>>')
_(output.data.keys).must_include(:focused_variables)
if %r{(Method: \#<Class:)(.*)\#a\(|\.a>}.match(output.task.inspect)
assert_includes output.data.keys, :focused_variables, output.task.inspect
else
_(output.data.keys).wont_include(:focused_variables)
end
Expand All @@ -167,7 +165,7 @@ def <<(value)
{ seq: [], message: 'WTF!' },
{ focus_on: { steps: alpha.method(:a) } }
],
)
)
end

_(output.gsub(/0x\w+/, "")).must_equal %{`-- #<Class:>
Expand Down Expand Up @@ -216,7 +214,7 @@ def <<(value)
},
}
],
)
)
end

_(output.gsub(/0x\w+/, "")).must_equal %{`-- #<Class:>
Expand Down Expand Up @@ -270,7 +268,7 @@ def <<(value)
},
}
],
)
)
end

_(output.gsub(/0x\w+/, "")).must_equal %{`-- #<Class:>
Expand Down
7 changes: 5 additions & 2 deletions test/trace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ class TraceTest < Minitest::Spec

renderer = ->(task_node:, position:, tree:) do
assert_equal tree[position], task_node

task = task_node.input.task
if task.is_a? Method
task = "#<Method: Trailblazer::Activity::Testing::Assertions::Implementing.#{task.name}>"
end
[
task_node.level,
%{#{task_node.level}/#{task_node.input.task}/#{task_node.output.data[:signal]}/#{task_node.value}/#{task_node.color}}
%{#{task_node.level}/#{task}/#{task_node.output.data[:signal]}/#{task_node.value}/#{task_node.color}}
]
end

Expand Down

0 comments on commit d3336f8

Please sign in to comment.