ariadne 0.0.4 → 0.0.5

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: 5d15963f0e72fcd20333f6227ced3e4dba5e3d5a7c2cc295440dcc98c9bb863a
4
- data.tar.gz: bd90b66bad183442d7661fd72566ef11223d45f705817bcae2b2026efc928a3a
3
+ metadata.gz: a71929c19a3e8fff0abc484843c1762edf12ecf6f45d90a6e0394cb4743aa243
4
+ data.tar.gz: e5959ac737aaf0392957164769dcb56e72ca73362da8431fcbb4a9d47fcc835b
5
5
  SHA512:
6
- metadata.gz: 42c4370c8b426696d7b336fc42e40c60509569f60e1260a37aa952c1ee013b8a0ef94784032907574d256eb53071e5d8563ec5a9539b555e5abb08d4165b4bff
7
- data.tar.gz: 30d1d3b263dee8c331d9f8d23b8bf8b9e422fd66b7f24a9488f2b4c3b8dc464a461201a0820475231628904a9a071d3ee496e8cd5cb27b0803818ecf2fce4bab
6
+ metadata.gz: 1bec945c8243605fb555b88e817c9cfe84268e06b4ae110ef2c5b472f86360deb5c91d4cfa3a8e3cf9220f90259bddcfe902fcd829fbe53d2090722bb6f454d9
7
+ data.tar.gz: fbb773617d74362a76c461c0c01283239175fea01d8915e3b810299b13b7849863cdefb1f8875592c3421da5a19945236736c7ec2df296a0d4fc72f8d666082c
data/lib/ariadne/log.rb CHANGED
@@ -1,14 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "open3"
4
- require "ariadne/helpers/text"
5
- require "ariadne/helpers/value_format"
4
+ require "ariadne/string/color"
6
5
 
7
6
  module Ariadne
8
7
  class Log
9
- include Helpers::Text
10
- include Helpers::ValueFormat
11
-
12
8
  def initialize(seam)
13
9
  @seam = seam
14
10
  end
@@ -26,54 +22,68 @@ module Ariadne
26
22
 
27
23
  def text
28
24
  @text ||=
29
- Text(
30
- [
31
- rank,
32
- " ",
33
- depth_dashes,
34
- class_name,
35
- prefix,
36
- method_name,
37
- parameters,
38
- return_value
39
- ].join
40
- )
25
+ [
26
+ rank,
27
+ " ",
28
+ depth_dashes,
29
+ class_name,
30
+ prefix,
31
+ method_name,
32
+ parameters,
33
+ return_value_type
34
+ ].join
41
35
  end
42
36
 
43
37
  def rank
44
- Text(@seam.rank.to_s.rjust(4)).gray
38
+ @seam.rank.to_s.rjust(4).gray
45
39
  end
46
40
 
47
41
  def depth_dashes
48
- Text("-" * @seam.depth).gray.tap { _1 << " " if @seam.depth.positive? }
42
+ ("-" * @seam.depth).gray.tap { _1 << " " if @seam.depth.positive? }
49
43
  end
50
44
 
51
45
  def class_name
52
- Text(@seam.klass.name).green
46
+ @seam.klass.name.green
53
47
  end
54
48
 
55
49
  def prefix
56
- Text(@seam.prefix).gray
50
+ @seam.prefix.gray
57
51
  end
58
52
 
59
53
  def method_name
60
- Text(@seam.method_name).cyan
54
+ @seam.method_name.to_s.cyan
61
55
  end
62
56
 
63
- def return_value
64
- value = Text(cast(@seam.return_value)).truncate(50)
65
- value = type(@seam.return_value) ? "<#{type(@seam.return_value)}> #{value}" : value
66
- Text(" -> #{value}").yellow
57
+ def return_value_type
58
+ value = type(@seam.return_value)
59
+ " -> #{value}".yellow
67
60
  end
68
61
 
69
62
  def parameters
70
- str =
71
- @seam.parameters.map do |parameter|
72
- arg = Text(cast(parameter.arg)).truncate(50)
73
- arg = type(parameter.arg) ? "<#{type(parameter.arg)}> #{arg}" : arg
74
- "#{parameter.param}: #{arg}"
75
- end.join(", ")
76
- Text(str.empty? ? "" : "(#{str})").magenta
63
+ return if @seam.parameters.empty?
64
+
65
+ [
66
+ "(",
67
+ @seam.parameters.flat_map { "#{_1.param}: #{arg(_1)}" }.join(", "),
68
+ ")"
69
+ ].join.magenta
70
+ end
71
+
72
+ def arg(parameter)
73
+ if parameter.type == :rest || %i[* ** &].include?(parameter.param)
74
+ parameter.arg.map { type(_1) }.join(", ")
75
+ else
76
+ type(parameter.arg)
77
+ end
78
+ end
79
+
80
+ def type(arg)
81
+ case arg
82
+ when "<?>" then "<?>"
83
+ when TrueClass, FalseClass then "Boolean"
84
+ when NilClass then "nil"
85
+ else arg.class.to_s
86
+ end
77
87
  end
78
88
  end
79
89
  end
data/lib/ariadne/seam.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "open3"
4
- require "ariadne/parameter"
5
4
 
6
5
  module Ariadne
7
6
  class Seam
8
7
  attr_reader :rank, :depth, :klass, :method_name, :prefix, :parameters, :return_value, :binding, :path
9
8
 
9
+ Parameter = Struct.new(:type, :param, :arg)
10
+
10
11
  class << self
11
12
  # We cannot make public methods because accessing the TracePoint
12
13
  # after it has been disabled would raise a RunTimeError
@@ -44,11 +45,23 @@ module Ariadne
44
45
 
45
46
  def parameters(tracepoint)
46
47
  method = tracepoint.self.method(tracepoint.method_id)
47
- method.parameters.map do |parameter|
48
- Parameter.new(parameter, binding: tracepoint.binding)
48
+ if forwarded_parameters?(method)
49
+ [Parameter.new(:rest, "...", ["<?>"])]
50
+ else
51
+ method.parameters.flat_map do |parameter|
52
+ type = parameter.first
53
+ param = parameter.last
54
+ arg = %i[* ** &].include?(param) ? ["<?>"] : tracepoint.binding.local_variable_get(param)
55
+ Parameter.new(type, param, arg)
56
+ rescue NameError
57
+ Parameter.new(type, param, type == :rest ? ["<?>"] : "<?>")
58
+ end
49
59
  end
50
- rescue NoMethodError
51
- []
60
+ end
61
+
62
+ # return true if method's signature is like `def my_method(...)`
63
+ def forwarded_parameters?(method)
64
+ method.parameters == [%i[rest *], %i[block &]]
52
65
  end
53
66
 
54
67
  def path(tracepoint)
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ module String
5
+ module Color
6
+ COLORS = %w[
7
+ black
8
+ red
9
+ green
10
+ yellow
11
+ blue
12
+ magenta
13
+ cyan
14
+ gray
15
+ ].freeze
16
+
17
+ COLORS.each.with_index do |color, index|
18
+ code = index + 30
19
+ define_method(color) do
20
+ "\e[#{code}m#{bleach}\e[0m"
21
+ end
22
+ bg_code = index + 40
23
+ define_method("bg_#{color}") do
24
+ "\e[#{bg_code}m#{bleach}\e[0m"
25
+ end
26
+ end
27
+
28
+ def bleach
29
+ gsub(/\e\[\d{1,2}m/, "")
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ String.include Ariadne::String::Color
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ariadne
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ariadne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Piron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2023-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,11 +102,9 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - lib/ariadne.rb
105
- - lib/ariadne/helpers/text.rb
106
- - lib/ariadne/helpers/value_format.rb
107
105
  - lib/ariadne/log.rb
108
- - lib/ariadne/parameter.rb
109
106
  - lib/ariadne/seam.rb
107
+ - lib/ariadne/string/color.rb
110
108
  - lib/ariadne/thread.rb
111
109
  - lib/ariadne/version.rb
112
110
  homepage: https://github.com/BigBigDoudou/ariadne
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- module Helpers
5
- module Text
6
- class Text < String
7
- COLORS = %w[
8
- black
9
- red
10
- green
11
- yellow
12
- blue
13
- magenta
14
- cyan
15
- gray
16
- ].freeze
17
-
18
- COLORS.each.with_index do |color, index|
19
- code = index + 30
20
- define_method(color) do
21
- "\e[#{code}m#{bleach}\e[0m"
22
- end
23
- bg_code = index + 40
24
- define_method("bg_#{color}") do
25
- "\e[#{bg_code}m#{bleach}\e[0m"
26
- end
27
- end
28
-
29
- def initialize(str)
30
- super(str.to_s)
31
- end
32
-
33
- def truncate(size)
34
- if self.size > size
35
- Text.new("#{self[..size]}...")
36
- else
37
- self
38
- end
39
- end
40
-
41
- def bleach
42
- gsub(/\e\[\d{1,2}m/, "")
43
- end
44
- end
45
-
46
- def Text(str) # rubocop:disable Naming/MethodName
47
- Text.new(str)
48
- end
49
- end
50
- end
51
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- module Helpers
5
- module ValueFormat
6
- RUBY_LITERALS = [
7
- NilClass,
8
- String,
9
- Integer,
10
- Float,
11
- Proc,
12
- TrueClass,
13
- FalseClass,
14
- Symbol,
15
- Array,
16
- Range,
17
- Regexp,
18
- Hash
19
- ].freeze
20
-
21
- def type(value)
22
- return if value.is_a?(Class) || RUBY_LITERALS.include?(value.class)
23
-
24
- value.class.name
25
- end
26
-
27
- def cast(value)
28
- case value
29
- when NilClass
30
- "nil"
31
- when Proc
32
- "#<Proc>"
33
- when Class
34
- value.name
35
- when String
36
- "\"#{value}\""
37
- else
38
- value.to_s
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "open3"
4
-
5
- module Ariadne
6
- class Parameter < SimpleDelegator
7
- def initialize(parameter, binding:)
8
- super(parameter)
9
- @binding = binding
10
- end
11
-
12
- def param
13
- last
14
- end
15
-
16
- def arg
17
- @binding.local_variable_get(last)
18
- rescue NameError
19
- "?"
20
- end
21
- end
22
- end