stackdo 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/stackdo.rb +106 -0
  3. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 518ca856c189d581320a3fb0aa822683ad66135b
4
+ data.tar.gz: f46cf3b418f31a2ddd1e17f17f21ead4526ce028
5
+ SHA512:
6
+ metadata.gz: 719507b5329c9ecd9796ef131272b66fe38d1e6bed8518078dd49baf8da87fc7095524ffbb03a0d8b97c30d912f5fb8a072fbae2b93393c8a78aace3b21780f7
7
+ data.tar.gz: 75b15cfdd3c045e7d4730393d28c99955d401b4475770a9b9d24dacc9fb314f3bdeaa5b084ee5d9093a272a0134789edc6c974dd80a9459f08e5554d85a33f45
data/lib/stackdo.rb ADDED
@@ -0,0 +1,106 @@
1
+ require 'binding_of_caller'
2
+
3
+ module Stackdo
4
+ class Error < StandardError; end
5
+
6
+ class Location < Struct.new(:file, :line)
7
+ def to_s
8
+ "#{file}:#{line}"
9
+ end
10
+ end
11
+
12
+ class MethodReference < Struct.new(:receiver, :name)
13
+ def to_s
14
+ case receiver
15
+ when Module then "#{receiver}.#{name}"
16
+ when Class then "#{receiver}##{name}"
17
+ else
18
+ receiver.to_s
19
+ end
20
+ end
21
+ end
22
+
23
+ class Variable
24
+ attr_reader :name, :value
25
+
26
+ def initialize(name, value)
27
+ @name = name
28
+ @value = value
29
+ end
30
+ end
31
+
32
+ class Environment
33
+ attr_reader :variables
34
+
35
+ def self.from_binding(binding)
36
+ local_variables = binding.local_variables.map do |local|
37
+ Variable.new(local, binding.local_variable_get(local))
38
+ end
39
+
40
+ Environment.new(
41
+ variables: local_variables,
42
+ )
43
+ end
44
+
45
+ def initialize(variables:)
46
+ @variables = variables
47
+ end
48
+ end
49
+
50
+ class Frame
51
+ attr_reader :location, :method_reference, :environment
52
+
53
+ def self.from_binding(binding)
54
+ file = binding.eval("__FILE__")
55
+ line = binding.eval("__LINE__")
56
+ method_name = binding.eval("__method__")
57
+
58
+ Stackdo::Frame.new(
59
+ location: Location.new(file, line),
60
+ method_reference: MethodReference.new(binding.receiver, method_name),
61
+ environment: Environment.from_binding(binding)
62
+ )
63
+ end
64
+
65
+ def initialize(location:, method_reference:, environment:)
66
+ @location = location
67
+ @method_reference = method_reference
68
+ @environment = environment
69
+ end
70
+ end
71
+
72
+ class CallStack
73
+ attr_reader :frames
74
+
75
+ def self.from_here
76
+ frames = Stackdo::call_stack_bindings(binding).map do |binding|
77
+ Stackdo::Frame.from_binding(binding)
78
+ end
79
+
80
+ CallStack.new(frames: frames)
81
+ end
82
+
83
+ def initialize(frames:)
84
+ @frames = frames
85
+ end
86
+
87
+ def walk(&block)
88
+ frames.each(&block)
89
+ end
90
+ end
91
+
92
+ def self.call_stack_bindings(binding)
93
+ bindings = []
94
+
95
+ n = 0
96
+ loop do
97
+ binding = binding.of_caller(n) rescue break
98
+ n += 1
99
+
100
+ bindings << binding
101
+ end
102
+
103
+ bindings
104
+ end
105
+ end
106
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stackdo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dylan McKay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'A library for getting detailed stacktraces (with variables).
14
+
15
+ '
16
+ email: dylanmckay34@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/stackdo.rb
22
+ homepage: https://github.com/dylanmckay/stackdo
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.5
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Advanced call stack retrieval
46
+ test_files: []
47
+ has_rdoc: