bindings 0.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/{MIT → LICENSE} +4 -2
- data/README.md +8 -8
- data/Rakefile +4 -0
- data/bindings.gemspec +11 -13
- data/ext/bindings/bindings.c +23 -0
- data/ext/bindings/extconf.rb +3 -0
- metadata +57 -37
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/certs/shreeve.pem +0 -21
- data/lib/bindings.rb +0 -43
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72e2c5b956d403ee05e92f14003659e38a420391
|
4
|
+
data.tar.gz: 1a7dc885b286f5795d38cd03b67ae7eebdc27c89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8079c96ab35de54367069bde8c3ef76429f1d1d193c333b7ec40822d0ce4b4f599cb6d85ad1c3d7e74332ec2ab77fa5e3be5b88ffa8bfbdd875d28645f502ecf
|
7
|
+
data.tar.gz: 9f38122e0d178df373c0789dad438d0d234c8ed1acf6d8a9cca5d663be762868632fc65082376d4bb130bf7ee5a56e93cbc148866831310b78f22cea649be78e
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.0
|
data/Gemfile
ADDED
data/{MIT → LICENSE}
RENAMED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Steve Shreeve
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -12,7 +14,7 @@ all copies or substantial portions of the Software.
|
|
12
14
|
|
13
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# bindings
|
2
2
|
|
3
|
-
|
3
|
+
```bindings``` is a Ruby gem that allows the bindings of calling methods to be accessed. Using this gem, you can easily access variables from calling methods, which makes it very easy to implement templating systems or other utilities that need similar access.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
To access variables or other attributes of calling methods, just call ```
|
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
8
|
|
9
9
|
## Example
|
10
10
|
|
@@ -28,11 +28,11 @@ end
|
|
28
28
|
class C
|
29
29
|
def c
|
30
30
|
c = 10
|
31
|
-
puts
|
32
|
-
puts
|
33
|
-
puts
|
34
|
-
puts
|
35
|
-
puts
|
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(999).eval('local_variables') rescue puts($!)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -46,7 +46,7 @@ c
|
|
46
46
|
b
|
47
47
|
a
|
48
48
|
outer
|
49
|
-
|
49
|
+
no such frame
|
50
50
|
```
|
51
51
|
|
52
52
|
## License
|
data/Rakefile
ADDED
data/bindings.gemspec
CHANGED
@@ -2,20 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "bindings"
|
5
|
-
s.version = "0.
|
6
|
-
s.
|
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"]
|
5
|
+
s.version = "1.0.0"
|
6
|
+
s.author = "Steve Shreeve"
|
15
7
|
s.email = "steve.shreeve@gmail.com"
|
8
|
+
s.summary = "Access the lexical binding scope of a calling method"
|
9
|
+
s.description = "This gem lets you access variables from a calling method."
|
10
|
+
s.homepage = "https://github.com/shreeve/bindings"
|
16
11
|
s.license = "MIT"
|
17
|
-
s.files = `git ls-files`.split("\n") - %w[.gitignore]
|
18
12
|
s.platform = Gem::Platform::RUBY
|
19
|
-
s.
|
20
|
-
s.
|
13
|
+
s.files = `git ls-files`.split("\n") - %w[.gitignore]
|
14
|
+
s.extensions << 'ext/bindings/extconf.rb'
|
15
|
+
s.add_development_dependency "bundler", "~> 1.5"
|
16
|
+
s.add_development_dependency "rake"
|
17
|
+
s.add_development_dependency "rake-compiler"
|
18
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
21
19
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#include "ruby/ruby.h"
|
2
|
+
#include "ruby/debug.h"
|
3
|
+
|
4
|
+
static VALUE
|
5
|
+
callback(const rb_debug_inspector_t *dbg_context, void *data)
|
6
|
+
{
|
7
|
+
long item = NUM2LONG(*((VALUE *)data));
|
8
|
+
return rb_debug_inspector_frame_binding_get(dbg_context, item + 1);
|
9
|
+
}
|
10
|
+
|
11
|
+
static VALUE
|
12
|
+
of_caller(VALUE self, VALUE item)
|
13
|
+
{
|
14
|
+
return rb_debug_inspector_open(callback, (void *) &item);
|
15
|
+
}
|
16
|
+
|
17
|
+
void
|
18
|
+
Init_bindings(VALUE self)
|
19
|
+
{
|
20
|
+
VALUE cBinding = rb_define_class("Binding", rb_cObject);
|
21
|
+
rb_define_singleton_method(cBinding, "of_caller", of_caller, 1); /* preferred */
|
22
|
+
rb_define_method(cBinding, "of_caller", of_caller, 1); /* backward compatibility */
|
23
|
+
}
|
metadata
CHANGED
@@ -1,52 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This gem lets you access variables from a calling method.
|
40
56
|
email: steve.shreeve@gmail.com
|
41
57
|
executables: []
|
42
|
-
extensions:
|
58
|
+
extensions:
|
59
|
+
- ext/bindings/extconf.rb
|
43
60
|
extra_rdoc_files: []
|
44
61
|
files:
|
45
|
-
-
|
62
|
+
- ".ruby-version"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
46
65
|
- README.md
|
66
|
+
- Rakefile
|
47
67
|
- bindings.gemspec
|
48
|
-
-
|
49
|
-
-
|
68
|
+
- ext/bindings/bindings.c
|
69
|
+
- ext/bindings/extconf.rb
|
50
70
|
homepage: https://github.com/shreeve/bindings
|
51
71
|
licenses:
|
52
72
|
- MIT
|
@@ -67,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
87
|
version: '0'
|
68
88
|
requirements: []
|
69
89
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.6.10
|
71
91
|
signing_key:
|
72
92
|
specification_version: 4
|
73
|
-
summary: Access
|
93
|
+
summary: Access the lexical binding scope of a calling method
|
74
94
|
test_files: []
|
checksums.yaml.gz.sig
DELETED
Binary file
|
data.tar.gz.sig
DELETED
Binary file
|
data/certs/shreeve.pem
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
-----BEGIN CERTIFICATE-----
|
2
|
-
MIIDhTCCAm2gAwIBAgIBATANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA1zdGV2
|
3
|
-
ZS5zaHJlZXZlMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
|
4
|
-
FgNjb20wHhcNMTUwNjEyMDMyMjM4WhcNMTYwNjExMDMyMjM4WjBEMRYwFAYDVQQD
|
5
|
-
DA1zdGV2ZS5zaHJlZXZlMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
|
6
|
-
k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCoT0lD
|
7
|
-
XoRFhnjFAtJ79NonyJxzMwq2s4TSnqrY25ElM2NoTcboCJ3eTgoeV/F1WSxGfEHs
|
8
|
-
xM00/ok/fMqFAZMIA8eV5+aaWze2q6/vE+/u+EI1dI9bogtGxu3FFuYUpVy5wha9
|
9
|
-
87U4HXPwXUbKS7bGQuTeJ07jO2okGCufbb+HNXABf+EEZCLk5fH9j1TGgu8fxq/X
|
10
|
-
vmVRKF/YpFEFM5TVv0dOO17vU/wOyBynjQ33AW8NHily163YjgIZR7mE042Hh9+G
|
11
|
-
w3Uq4L5ytgSoVDIs+owm5NLt0G13EjmsZUBszVErJ+byg62VjiAjSL4DQJSrlCsU
|
12
|
-
UuTSvTtx7Ez1nvKtAgMBAAGjgYEwfzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAd
|
13
|
-
BgNVHQ4EFgQU41cP4dVdL49Hzswd3/gCzX3+z3swIgYDVR0RBBswGYEXc3RldmUu
|
14
|
-
c2hyZWV2ZUBnbWFpbC5jb20wIgYDVR0SBBswGYEXc3RldmUuc2hyZWV2ZUBnbWFp
|
15
|
-
bC5jb20wDQYJKoZIhvcNAQEFBQADggEBAIaDzT/cGpJJT9eyhovk1ScwTA1jocDR
|
16
|
-
bIs/mNbQN6XlkipOtxCcx9XvVuwEZtP8/UeX+SKBHAtTnFf4Dez7vjSQAaVLZQe7
|
17
|
-
uXuX+S4LFTTf0oFVznQaMQ7PbqKqCmtof+1MqNpDTPTayxrlNUTPl3SpkW6bv4qi
|
18
|
-
hWz+RgGCWYc9TQ+JigLPbsfJpok31sHXrCztMb/KMbTozGTGswljbpuSq7Lzs9rp
|
19
|
-
4PkbTeqnzZJmSZjUBwvnQFNhXY08hPUs7aASHu9deACBbOBY+Hg6tiSOdfw50uYS
|
20
|
-
ksjokeQosImFuxgjMrlyoRcpbZmyfQ33yImqtLH6FMWF3hpoxJq9wPk=
|
21
|
-
-----END CERTIFICATE-----
|
data/lib/bindings.rb
DELETED
@@ -1,43 +0,0 @@
|
|
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.gz.sig
DELETED
Binary file
|