binding_of_callers 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50592668cad4ca1e8716b00e2c3c08e0f50029d0
4
+ data.tar.gz: d655875798fdb8572d3a7cbf266950dc6e7a37c9
5
+ SHA512:
6
+ metadata.gz: '038b883b9922432f5c1db10d14dfba025c075f32636c879bdf1709c712e5736690358d7b620c5a2a04afe04de2b2ab2917ffbacbfcdfb5a963196a4d08ecc4fa'
7
+ data.tar.gz: '09182e5dc90a063ba1140e24287e33d9b7811f8869bbb9644e6c41b9545abd7e143927a8525d31e18f5243abd3d736c3fd182b1d94e0f3ec561c405948da11e6'
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
11
+ *.gem
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at block24block@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in binding_of_callers.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 ken
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,104 @@
1
+ # BindingOfCallers
2
+
3
+ Something like [binding_of_caller](https://github.com/banister/binding_of_caller "binding_of_caller"), but collect all binding of callers at once
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'binding_of_callers'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install binding_of_callers
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ binding.of_callers # => an array of wrapped binding of callers
25
+ binding.of_callers! # => an array of extended binding of callers
26
+ ```
27
+
28
+ ### Inspect and modify a binding
29
+
30
+ ```ruby
31
+ require 'binding_of_callers'
32
+
33
+ class Test
34
+ def a
35
+ var, @ivar, arr = 1, 2, []
36
+ b
37
+ p var, @ivar
38
+ p arr
39
+ end
40
+
41
+ def b
42
+ c
43
+ end
44
+
45
+ def c
46
+ a_bind = binding.of_callers![2]
47
+ p a_bind
48
+ p a_bind.iv, a_bind.lv
49
+
50
+ a_bind.lv :var, 'hello'
51
+ a_bind.iv :@ivar, 'world'
52
+ a_bind.lv(:arr) << 'bye' << 'world'
53
+ end
54
+ end
55
+
56
+ Test.new.a
57
+
58
+ # OUTPUT
59
+ # #<Binding:78145200 Test#a test.rb:6>
60
+ # {:@ivar=>2}
61
+ # {:var=>1, :arr=>[]}
62
+ # "hello"
63
+ # "world"
64
+ # ["bye", "world"]
65
+ ```
66
+
67
+ ### Work with pry, get binding of callers from `_bs_`
68
+
69
+ ```ruby
70
+ require 'binding_of_callers/pry'
71
+
72
+ class Test
73
+ def a
74
+ var, @ivar, arr = 1, 2, []
75
+ b
76
+ p var, @ivar
77
+ p arr
78
+ end
79
+
80
+ def b
81
+ c
82
+ end
83
+
84
+ def c
85
+ binding.pry
86
+ end
87
+ end
88
+
89
+ Test.new.a
90
+
91
+ # IN PRY
92
+ # From: /tmp/test_pry.rb @ line 16 Test#c:
93
+ #
94
+ # 15: def c
95
+ # => 16: binding.pry
96
+ # 17: end
97
+ #
98
+ # [1] pry(#<Test>)> _bs_
99
+ # [#<Binding:76752040 Test#c test_pry.rb:16>,
100
+ # #<Binding:76751000 Test#b test_pry.rb:12>,
101
+ # #<Binding:76734010 Test#a test_pry.rb:6>,
102
+ # #<Binding:76732930 Object#<main> test_pry.rb:20>]
103
+ ```
104
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "binding_of_callers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'binding_of_callers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "binding_of_callers"
8
+ spec.version = BindingOfCallers::VERSION
9
+ spec.authors = ["ken"]
10
+ spec.email = ["block24block@gmail.com"]
11
+
12
+ spec.summary = %q{a wrapper of binding_of_caller, for easy use}
13
+ spec.homepage = 'https://github.com/turnon/binding_of_callers'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+
27
+ spec.add_dependency "binding_of_caller", "~> 0.7"
28
+ spec.add_dependency "pry", "~> 0.10.4"
29
+ end
@@ -0,0 +1,35 @@
1
+ require "binding_of_callers/version"
2
+ require 'binding_of_callers/revealed'
3
+ require 'binding_of_caller'
4
+
5
+ class Binding
6
+
7
+ def of_callers
8
+ enhance do |bi|
9
+ BindingOfCallers::Revealed.new bi
10
+ end
11
+ end
12
+
13
+ def of_callers!
14
+ enhance do |bi|
15
+ bi.extend BindingOfCallers::Reveal
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def enhance &enhance
22
+ collected.map(&enhance)
23
+ end
24
+
25
+ def collected
26
+ n = 3
27
+ bis = []
28
+ while n < frame_count
29
+ bis << of_caller(n)
30
+ n = n.succ
31
+ end
32
+ bis
33
+ end
34
+
35
+ end
@@ -0,0 +1,12 @@
1
+ require 'binding_of_callers'
2
+ require 'pry'
3
+
4
+ class Binding
5
+ def pry(object=nil, hash={})
6
+ bs = of_callers!.tap &:shift
7
+ Pry.hooks.add_hook :when_started, "original_binding_stack_#{object_id}" do |target, options, pry_self|
8
+ pry_self.inject_local :_bs_, bs, pry_self.current_binding
9
+ end
10
+ Pry.start self
11
+ end
12
+ end
@@ -0,0 +1,100 @@
1
+ module BindingOfCallers
2
+ module Reveal
3
+
4
+ def _binding
5
+ instance_variable_defined?(:@_binding) ? @_binding : self
6
+ end
7
+
8
+ def inspect
9
+ "#<#{self.class}:#{object_id} #{klass}#{call_symbol}#{frame_env} #{file}:#{line}>"
10
+ end
11
+
12
+ def iv *args
13
+ case args.count
14
+ when 0
15
+ all_iv
16
+ when 1
17
+ the_iv args[0]
18
+ when 2
19
+ set_iv(*args)
20
+ end
21
+ end
22
+
23
+ def lv *args
24
+ case args.count
25
+ when 0
26
+ all_lv
27
+ when 1
28
+ the_lv args[0]
29
+ when 2
30
+ set_lv(*args)
31
+ end
32
+ end
33
+
34
+ def klass
35
+ @klass ||= _binding.eval(singleton_method? ? 'self' : 'self.class')
36
+ end
37
+
38
+ def singleton_method?
39
+ return @sm if instance_variable_defined? :@sm
40
+ class_name = _binding.eval 'self.class.name'
41
+ @sm = (class_name == 'Module' or class_name == 'Class')
42
+ end
43
+
44
+ def call_symbol
45
+ @call_sym ||= singleton_method? ? '.' : '#'
46
+ end
47
+
48
+ def file
49
+ _binding.eval('__FILE__')
50
+ end
51
+
52
+ def line
53
+ _binding.eval('__LINE__')
54
+ end
55
+
56
+ def frame_env
57
+ _binding.frame_description
58
+ end
59
+
60
+ def env_type
61
+ _binding.frame_type
62
+ end
63
+
64
+ private
65
+
66
+ def all_iv
67
+ _binding.eval <<-EOS
68
+ instance_variables.each_with_object({}) do |iv_name, vars|
69
+ vars[iv_name] = instance_variable_get(iv_name)
70
+ end
71
+ EOS
72
+ end
73
+
74
+ def the_iv name
75
+ binding_self.instance_variable_get name
76
+ end
77
+
78
+ def set_iv name, value
79
+ binding_self.instance_variable_set name, value
80
+ end
81
+
82
+ def binding_self
83
+ _binding.eval "self"
84
+ end
85
+
86
+ def all_lv
87
+ _binding.local_variables.each_with_object({}) do |lv_name, vars|
88
+ vars[lv_name] = the_lv lv_name
89
+ end
90
+ end
91
+
92
+ def the_lv name
93
+ _binding.local_variable_get name
94
+ end
95
+
96
+ def set_lv name, value
97
+ _binding.local_variable_set name, value
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,13 @@
1
+ require 'binding_of_callers/reveal'
2
+
3
+ module BindingOfCallers
4
+ class Revealed
5
+
6
+ include Reveal
7
+
8
+ def initialize _binding
9
+ @_binding = _binding
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module BindingOfCallers
2
+ VERSION = "0.1.3"
3
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binding_of_callers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - ken
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-05 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: binding_of_caller
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.4
83
+ description:
84
+ email:
85
+ - block24block@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - binding_of_callers.gemspec
100
+ - lib/binding_of_callers.rb
101
+ - lib/binding_of_callers/pry.rb
102
+ - lib/binding_of_callers/reveal.rb
103
+ - lib/binding_of_callers/revealed.rb
104
+ - lib/binding_of_callers/version.rb
105
+ homepage: https://github.com/turnon/binding_of_callers
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.8
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: a wrapper of binding_of_caller, for easy use
129
+ test_files: []