bindings 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/MIT +19 -0
- data/README.md +54 -0
- data/bindings.gemspec +21 -0
- data/certs/shreeve.pem +21 -0
- data/lib/bindings.rb +43 -0
- metadata +74 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d49321d41eecde85f7b310ccc5d14502df74276c
|
4
|
+
data.tar.gz: 4d329d17a6e86eac25fc8d0d0236ac89a51fdcef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 406ae0963a2432d4ed353ced76ef594234003c5647bd6e434fb971613fb674c2fd95d52c29ee1359fbd2d45623f065908af4ca2c987cb36248e8759c37177529
|
7
|
+
data.tar.gz: bb523b58f4d12f1d2d3e4fa282e4152be75ebd5d5357f8c5b26270323ddf52946318881e7050502ce2203d719fca04b08d23936988bdfcee2f375fd4be89c56f
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/MIT
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 Steve Shreeve <steve.shreeve@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# bindings
|
2
|
+
|
3
|
+
Access bindings of calling methods (uses fiddle instead of C calls).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
To access variables or other attributes of calling methods, just call ```binding.of_caller(n)``` where ```n``` is a number that represents how many callers back you are requesting.
|
8
|
+
|
9
|
+
## Example
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
outer = 40
|
13
|
+
|
14
|
+
class A
|
15
|
+
def a
|
16
|
+
a = 30
|
17
|
+
B.new.b
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class B
|
22
|
+
def b
|
23
|
+
b = 20
|
24
|
+
C.new.c
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class C
|
29
|
+
def c
|
30
|
+
c = 10
|
31
|
+
puts binding.of_caller(0).eval('local_variables') # c
|
32
|
+
puts binding.of_caller(1).eval('local_variables') # b
|
33
|
+
puts binding.of_caller(2).eval('local_variables') # a
|
34
|
+
puts binding.of_caller(3).eval('local_variables') # outer
|
35
|
+
puts binding.of_caller(9).eval('local_variables') rescue puts($!)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
A.new.a
|
40
|
+
```
|
41
|
+
|
42
|
+
## Result
|
43
|
+
|
44
|
+
```
|
45
|
+
c
|
46
|
+
b
|
47
|
+
a
|
48
|
+
outer
|
49
|
+
No such frame, gone beyond end of stack!
|
50
|
+
```
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
This software is licensed under terms of the MIT License.
|
data/bindings.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "bindings"
|
5
|
+
s.version = "0.9"
|
6
|
+
s.summary = "Access bindings of calling methods (uses fiddle instead of C calls)."
|
7
|
+
s.description = <<-EOT
|
8
|
+
This gem allows the bindings of calling methods to be accessed without a C extension.
|
9
|
+
It does this by using fiddle, Ruby's built-in support for accessing native C methods.
|
10
|
+
Using this gem, you can easily access variables from calling methods, which makes it
|
11
|
+
very easy to implement templating system or other utilities that need similar access.
|
12
|
+
EOT
|
13
|
+
s.homepage = "https://github.com/shreeve/bindings"
|
14
|
+
s.authors = ["Steve Shreeve"]
|
15
|
+
s.email = "steve.shreeve@gmail.com"
|
16
|
+
s.license = "MIT"
|
17
|
+
s.files = `git ls-files`.split("\n") - %w[.gitignore]
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.cert_chain = ["certs/shreeve.pem"]
|
20
|
+
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
|
21
|
+
end
|
data/certs/shreeve.pem
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDhTCCAm2gAwIBAgIBATANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA1zdGV2
|
3
|
+
ZS5zaHJlZXZlMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
|
4
|
+
FgNjb20wHhcNMTUwNjEyMDMyMjM4WhcNMTYwNjExMDMyMjM4WjBEMRYwFAYDVQQD
|
5
|
+
DA1zdGV2ZS5zaHJlZXZlMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
|
6
|
+
k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA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rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# =============================================================================
|
2
|
+
# bindings: Access bindings of calling methods (uses fiddle instead of C calls)
|
3
|
+
#
|
4
|
+
# Author: Steve Shreeve <steve.shreeve@gmail.com>
|
5
|
+
# Date: June 13, 2015
|
6
|
+
# Legal: MIT License
|
7
|
+
# =============================================================================
|
8
|
+
|
9
|
+
require 'fiddle/import'
|
10
|
+
|
11
|
+
module Fiddle
|
12
|
+
module Binding
|
13
|
+
extend Fiddle::Importer
|
14
|
+
|
15
|
+
dlload Fiddle.dlopen(nil)
|
16
|
+
|
17
|
+
extern "void* rb_debug_inspector_open(void*, void*)"
|
18
|
+
bind("void* callback(void*, void*)") {|ptr, _| DebugStruct.new(ptr).contexts }
|
19
|
+
|
20
|
+
DebugStruct = struct [
|
21
|
+
"void* thread",
|
22
|
+
"void* frame",
|
23
|
+
"void* backtrace",
|
24
|
+
"void* contexts",
|
25
|
+
"long backtrace_size"
|
26
|
+
]
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def callers
|
30
|
+
list = rb_debug_inspector_open(self['callback'], nil).to_value
|
31
|
+
list.drop(4).map {|ary| ary[2]}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class ::Binding
|
38
|
+
def of_caller(n)
|
39
|
+
c = ::Fiddle::Binding.callers
|
40
|
+
n < c.size or raise "No such frame, gone beyond end of stack!"
|
41
|
+
c[n]
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bindings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.9'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Shreeve
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDhTCCAm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jSQAaVLZQe7
|
28
|
+
uXuX+S4LFTTf0oFVznQaMQ7PbqKqCmtof+1MqNpDTPTayxrlNUTPl3SpkW6bv4qi
|
29
|
+
hWz+RgGCWYc9TQ+JigLPbsfJpok31sHXrCztMb/KMbTozGTGswljbpuSq7Lzs9rp
|
30
|
+
4PkbTeqnzZJmSZjUBwvnQFNhXY08hPUs7aASHu9deACBbOBY+Hg6tiSOdfw50uYS
|
31
|
+
ksjokeQosImFuxgjMrlyoRcpbZmyfQ33yImqtLH6FMWF3hpoxJq9wPk=
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2015-06-14 00:00:00.000000000 Z
|
34
|
+
dependencies: []
|
35
|
+
description: |
|
36
|
+
This gem allows the bindings of calling methods to be accessed without a C extension.
|
37
|
+
It does this by using fiddle, Ruby's built-in support for accessing native C methods.
|
38
|
+
Using this gem, you can easily access variables from calling methods, which makes it
|
39
|
+
very easy to implement templating system or other utilities that need similar access.
|
40
|
+
email: steve.shreeve@gmail.com
|
41
|
+
executables: []
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- MIT
|
46
|
+
- README.md
|
47
|
+
- bindings.gemspec
|
48
|
+
- certs/shreeve.pem
|
49
|
+
- lib/bindings.rb
|
50
|
+
homepage: https://github.com/shreeve/bindings
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.4.7
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Access bindings of calling methods (uses fiddle instead of C calls).
|
74
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|