pry-memory 0.1.0

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: 15b0325065403f0e3795f6c3127a10decd627a7d
4
+ data.tar.gz: 122168b123e302416aa7b1185b8d3f0e663cda1b
5
+ SHA512:
6
+ metadata.gz: 77150697abc35e74c37f291cbe94df058f09dc26cf4b4c30ddc82551982d0f4b018dfea3f824fb245614b0be78cc7c42ce2cd81d74ce5b153e5d76fbf9bdb03e
7
+ data.tar.gz: 1bde3a9dc470d64f28cc86e065684ffc3301d447599a2d1d169fc7514198a44853bf338fad7e643a9432c033cf15741056c96ce223d01a74684c24c4ca5ee773
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
11
+ .ruby-gemset
12
+ .rvmrc
13
+ .rspec
14
+ .pryrc
15
+
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pry-memory.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ilya Bylich
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,83 @@
1
+ # Pry::Memory
2
+
3
+ A tiny gem for automated naming of stuff typed in the console:
4
+
5
+ ```
6
+ [1] pry(main)> a = > 1
7
+ => 1
8
+ [2] pry(main)> b = > 2
9
+ => 2
10
+ [3] pry(main)> c = > 3
11
+ => 3
12
+ [4] pry(main)> d = > a + b + c
13
+ => 6
14
+ [5] pry(main)> e = >
15
+ ```
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'pry-memory'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install pry-memory
32
+
33
+ ## Usage
34
+
35
+ This gem will be automatically required with `require 'pry'` once you put into your Gemfile.
36
+
37
+ ### Configuration
38
+
39
+ Put this to your `.pryrc` file (bundler is not available in `.pryrc`, so we have to require the gem manually):
40
+ ``` ruby
41
+ require 'pry/memory'
42
+ Pry::Memory.start(:abc)
43
+ ```
44
+
45
+ And run `pry`.
46
+
47
+ ### Customization
48
+
49
+ `:abc` is a stupid name of strategy that generates lower case letter (a,b,c,...).
50
+ Also this gem has pre-defined strategy `:a1a2` that generates (a1,a2,a3,...):
51
+ ```
52
+ [1] pry(main)> a1 = > 1
53
+ => 1
54
+ [2] pry(main)> a2 = > 2
55
+ => 2
56
+ [3] pry(main)> a3 = > 3
57
+ => 3
58
+ [4] pry(main)> a4 = > a1 + a2 + a3
59
+ ```
60
+
61
+ You can write your own strategy:
62
+ ``` ruby
63
+ Pry::Memory.start do |counter|
64
+ # generate a variable name here
65
+ # you can use counter here, but it's not necessary at all
66
+ # in fact, you can generate a random letters here
67
+ # or even random words :)
68
+ end
69
+ ```
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( https://github.com/[my-github-username]/pry-memory/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pry/memory"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require 'pry/memory'
@@ -0,0 +1,31 @@
1
+ require "pry/memory/version"
2
+
3
+ class Pry
4
+ module Memory
5
+ autoload :Hook, 'pry/memory/hook'
6
+ autoload :Generators, 'pry/memory/generators'
7
+ autoload :Strategy, 'pry/memory/strategy'
8
+ autoload :Prompt, 'pry/memory/prompt'
9
+
10
+ class << self
11
+ # Runs some patches
12
+ # and prepares pry for storing all
13
+ # evaluated variables
14
+ #
15
+ def start(strategy = nil, &block)
16
+ Strategy.configure(strategy, &block)
17
+ Prompt.replace
18
+ Hook.register
19
+ end
20
+
21
+ # Stops all activity
22
+ # and restore patched configuration
23
+ # to its original state
24
+ #
25
+ def stop
26
+ Prompt.restore
27
+ Hook.unregister
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ # Module for generating generators (yes-yes)
2
+ #
3
+ # @example
4
+ # g = Pry::Memory::Generators.new { |counter| counter * 2}
5
+ # g.generate
6
+ # # => 2
7
+ # g.next!; g.generate
8
+ # # => 4
9
+ #
10
+ # Two commonly used (probably) strategies are pre-defined:
11
+ # 1. :abc - generates a/b/c/d... sequence
12
+ # 2. :a1a2 - generates a1/a2/a3... sequence
13
+ #
14
+ module Pry::Memory::Generators
15
+ extend self
16
+
17
+ def counter
18
+ @counter ||= 1
19
+ end
20
+ attr_writer :counter
21
+
22
+ def reset_counter!
23
+ @counter = 1
24
+ end
25
+
26
+ def new(&block)
27
+ Class.new do
28
+ define_method :generate do
29
+ block.call(Pry::Memory::Generators.counter)
30
+ end
31
+
32
+ define_method :next! do
33
+ Pry::Memory::Generators.counter += 1
34
+ end
35
+ end.new
36
+ end
37
+
38
+ PREDEFINED = {
39
+ :abc => new { |counter| ('a'..'z').to_a[counter - 1] },
40
+ :a1a2 => new { |counter| "a#{counter}" }
41
+ }
42
+ end
@@ -0,0 +1,29 @@
1
+ # Class responsible for adding hook to pry
2
+ #
3
+ # @example
4
+ # Pry::Memory::Hook.register
5
+ # # hook registered
6
+ # Pry::Memory::Hook.unregister
7
+ # # hook unregister
8
+ #
9
+ module Pry::Memory::Hook
10
+ extend self
11
+
12
+ PRY_HOOK = :after_eval
13
+ HOOK_NAME = 'pry-memory'
14
+
15
+ def register
16
+ Pry.hooks.add_hook PRY_HOOK, HOOK_NAME do |result, pry_instance|
17
+ if result
18
+ pry_binding = pry_instance.current_binding
19
+ variable_name = Pry::Memory::Strategy.variable_name
20
+ pry_binding.local_variable_set(variable_name, result)
21
+ Pry::Memory::Strategy.next!
22
+ end
23
+ end
24
+ end
25
+
26
+ def unregister
27
+ Pry.hooks.delete_hook(PRY_HOOK, HOOK_NAME)
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ # Class responsible for replacing default prompt
2
+ #
3
+ # @example
4
+ # Pry::Memory::Prompt.replace
5
+ # # => prompt replaced
6
+ # Pry::Memory::Prompt.restore
7
+ # # => prompt restopred to the previous one
8
+ #
9
+ module Pry::Memory::Prompt
10
+ extend self
11
+
12
+ PROMPT = [
13
+ proc { |target_self, nest_level, pry|
14
+ was = Pry::DEFAULT_PROMPT[0].call(target_self, nest_level, pry)
15
+ extra = (nest_level.zero? ? "#{Pry::Memory::Strategy.variable_name} = > " : '0')
16
+ was + extra
17
+ },
18
+ proc { |target_self, nest_level, pry|
19
+ was = Pry::DEFAULT_PROMPT[1].call(target_self, nest_level, pry)
20
+ extra = (nest_level.zero? ? "#{Pry::Memory::Strategy.variable_name} = > " : '0')
21
+ was + extra
22
+ }
23
+ ]
24
+
25
+ def replace
26
+ @old_prompt = Pry.prompt
27
+ Pry.prompt = PROMPT
28
+ end
29
+
30
+ def restore
31
+ Pry.prompt = Pry::DEFAULT_PROMPT
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ # Class responsible for generating
2
+ # variable names
3
+ #
4
+ # @example
5
+ # Pry::Memory::Strategy.variable_name
6
+ # # => 'a'
7
+ # Pry::Memory::Strategy.next!
8
+ # Pry::Memory::Strategy.variable_name
9
+ # # => 'b'
10
+ #
11
+ module Pry::Memory::Strategy
12
+ extend self
13
+
14
+ def configure(strategy, &block)
15
+ @strategy = if strategy
16
+ Pry::Memory::Generators::PREDEFINED[strategy]
17
+ elsif block_given?
18
+ Pry::Memory::Generators.new(&block)
19
+ else
20
+ raise "Strategy must be specified using Symbol or block"
21
+ end
22
+ end
23
+
24
+ attr_reader :strategy
25
+ def variable_name
26
+ strategy.generate
27
+ end
28
+
29
+ def next!
30
+ strategy.next!
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ class Pry
2
+ module Memory
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pry/memory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pry-memory"
8
+ spec.version = Pry::Memory::VERSION
9
+ spec.authors = ["Ilya Bylich"]
10
+ spec.email = ["ibylich@gmail.com"]
11
+
12
+ spec.summary = %q{PRy extension for automated naming of everything that you type in console.}
13
+ spec.homepage = "https://github.com/iliabylich/pry-memory"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'pry', '~> 0.10.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_development_dependency 'rspec', '~> 3.3.0'
27
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-memory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Bylich
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.0
69
+ description:
70
+ email:
71
+ - ibylich@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/pry-memory.rb
86
+ - lib/pry/memory.rb
87
+ - lib/pry/memory/generators.rb
88
+ - lib/pry/memory/hook.rb
89
+ - lib/pry/memory/prompt.rb
90
+ - lib/pry/memory/strategy.rb
91
+ - lib/pry/memory/version.rb
92
+ - pry-memory.gemspec
93
+ homepage: https://github.com/iliabylich/pry-memory
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.7
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: PRy extension for automated naming of everything that you type in console.
117
+ test_files: []