pry-command-set-registry 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05d4205804afc01b492f5cb8eb27d6dd04cfdc92
4
+ data.tar.gz: 2ca8db0ba026143442b230cfb204021ed8023763
5
+ SHA512:
6
+ metadata.gz: d3402499952d253cf878d1c3d6dbc51bab67264b3f6858e4c5e224a9d34b4e3861407a5c082429b3402be15fa98a66c002f90588d33566055d68f80051111153
7
+ data.tar.gz: d3cffdcf66b28b058032b68dbe3120bc0a145036e711c751ec73e9de4225356123ae9e85566960c0f66f447bc6e284b3cdc909f233d9c5dc923c3bc4b7843be5
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "guard"
7
+ gem "guard-minitest"
8
+ gem "minitest", ">= 3.0"
9
+ gem "mocha"
10
+ end
@@ -0,0 +1,6 @@
1
+ guard(:minitest, :all_after_pass => false, :all_on_start => false) do
2
+ watch(%r{^lib/pry[_\-]command[_\-]set[_\-]registry\.rb$}) { "test" }
3
+ watch(%r{^lib/pry_command_set_registry/(.+)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
4
+ watch(%r{^test/.+_test\.rb$})
5
+ watch(%r{^test/test_helper\.rb$}) { "test" }
6
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Danny Guinther
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # PryCommandSetRegistry
2
+
3
+ Plugin for managing registration and loading of command sets in pry.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pry-command-set-registry'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pry-command-set-registry
18
+
19
+ ## Usage
20
+
21
+ Require library file:
22
+
23
+ ```ruby
24
+ require "pry-command-set-registry"
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/tdg5/pry-command-set-registry/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.pattern = "test/**/*_test.rb"
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ require "pry"
2
+ require "pry_command_set_registry"
@@ -0,0 +1,17 @@
1
+ require "pry"
2
+ require "pry_command_set_registry/version"
3
+ require "pry_command_set_registry/registry"
4
+ require "pry_command_set_registry/command_set"
5
+ require "pry_command_set_registry/commands"
6
+
7
+ module PryCommandSetRegistry
8
+ class << self
9
+ extend Forwardable
10
+ attr_accessor :registry
11
+ def_delegators :registry, :command_set, :command_sets, :define_command_set
12
+ end
13
+ self.registry ||= Registry.new
14
+ private_class_method :registry=
15
+ end
16
+
17
+ Pry.commands.import(PryCommandSetRegistry::Commands)
@@ -0,0 +1,19 @@
1
+ module PryCommandSetRegistry
2
+ class CommandSet < Pry::CommandSet
3
+ attr_reader :commands, :description, :name
4
+
5
+ def initialize(name, description, &block)
6
+ raise "Block required!" unless block_given?
7
+ super(&block)
8
+ @description = description
9
+ @name = name.to_s
10
+ apply_group_name_to_commands
11
+ end
12
+
13
+ private
14
+
15
+ def apply_group_name_to_commands
16
+ commands.values.each { |command| command.group(name) }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module PryCommandSetRegistry
2
+ desc = "Commands for interacting with the Pry command set registry"
3
+ Commands = CommandSet.new("PryCommandSetRegistry", desc) do
4
+ command("import-set", "Import a Pry command set") do |command_set_name|
5
+ raise Pry::CommandError, "Provide a command set name" if command_set_name.nil?
6
+
7
+ begin
8
+ set = target.eval(command_set_name)
9
+ rescue NameError
10
+ set = PryCommandSetRegistry.command_set(command_set_name)
11
+ ::Kernel.raise if set.nil?
12
+ end
13
+ _pry_.commands.import(set)
14
+ end
15
+
16
+ command("list-sets", "List registered command sets") do
17
+ _pry_.output.puts "Registered Command Sets:"
18
+ _pry_.output.puts format_command_set_listing(PryCommandSetRegistry.command_sets)
19
+ end
20
+
21
+ helpers do
22
+ def format_command_set_listing(command_sets)
23
+ return "" if command_sets.none?
24
+ max_len = command_sets.keys.max_by(&:length).length
25
+ sets = command_sets.map do |set_name, set|
26
+ " #{set_name.ljust(max_len)} - #{set.description}"
27
+ end
28
+ sets.join("\n")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module PryCommandSetRegistry
2
+ class Registry
3
+ attr_reader :command_sets
4
+
5
+ def initialize
6
+ @command_sets = {}
7
+ end
8
+
9
+ def command_set(name)
10
+ sanitized_name = name.to_s.sub(/^:/, "")
11
+ command_sets[sanitized_name]
12
+ end
13
+
14
+ def define_command_set(name, description, &block)
15
+ command_set = CommandSet.new(name, description, &block)
16
+ command_sets[command_set.name] = command_set
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module PryCommandSetRegistry
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pry_command_set_registry/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pry-command-set-registry"
8
+ spec.version = PryCommandSetRegistry::VERSION
9
+ spec.authors = ["Danny Guinther"]
10
+ spec.email = ["dannyguinther@gmail.com"]
11
+ spec.summary = %q{Plugin for managing registration and loading of command sets in pry.}
12
+ spec.description = %q{Plugin for managing registration and loading of command sets in pry.}
13
+ spec.homepage = "https://github.com/tdg5/pry-command-set-registry"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(test)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+
23
+ spec.add_dependency "pry"
24
+ end
@@ -0,0 +1,15 @@
1
+ require "minitest/autorun"
2
+ require "mocha/setup"
3
+ require "pry_command_set_registry"
4
+
5
+ # Use alternate shoulda-style DSL for tests
6
+ module PryCommandSetRegistry
7
+ class TestCase < Minitest::Spec
8
+ class << self
9
+ alias :setup :before
10
+ alias :teardown :after
11
+ alias :context :describe
12
+ alias :should :it
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+
3
+ class CommandSetTest < PryCommandSetRegistry::TestCase
4
+ Subject = PryCommandSetRegistry::CommandSet
5
+
6
+ context "instance methods" do
7
+ context "#initialize" do
8
+ setup do
9
+ @name = "Foo"
10
+ @description = "Bar"
11
+ @command_set_proc = default_command_set_proc
12
+ end
13
+
14
+ should "create a new instance from the given arguments" do
15
+ instance = Subject.new(@name, @description, &@command_set_proc)
16
+
17
+ assert_equal @name, instance.name
18
+ assert_equal @description, instance.description
19
+ assert_equal true, @command_set_proc_obj[:proc_called]
20
+ end
21
+
22
+ should "correctly initialize the command set" do
23
+ instance = Subject.new(@name, @description, &@command_set_proc)
24
+ instance.run_command({}, "test")
25
+ assert_equal true, @command_set_proc_obj[:command_called]
26
+ end
27
+
28
+ should "correctly set group names" do
29
+ instance = Subject.new(@name, @description, &@command_set_proc)
30
+ assert_equal @name, instance.commands.values.first.group
31
+ end
32
+ end
33
+ end
34
+
35
+ # Proc is called with instance eval, so closure must be used to allow
36
+ # referencing in test and in command proc.
37
+ def default_command_set_proc
38
+ @command_set_proc_obj = closure_obj = {
39
+ :command_called => false,
40
+ :proc_called => false,
41
+ }
42
+ proc do
43
+ closure_obj[:proc_called] = true
44
+ command("test", "test command") do
45
+ closure_obj[:command_called] = true
46
+ end
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,81 @@
1
+ require "test_helper"
2
+
3
+ class CommandsTest < PryCommandSetRegistry::TestCase
4
+ context "import-set" do
5
+ should "raise Pry::CommandError if no set name is given" do
6
+ assert_raises(Pry::CommandError) do
7
+ Pry.commands.run_command({}, "import-set")
8
+ end
9
+ end
10
+
11
+ should "raise NameError if caught NameError doesn't match command set" do
12
+ context = Pry.binding_for(Object.new)
13
+ assert_raises(NameError) do
14
+ Pry.commands.run_command({ :target => context }, "import-set", "command_set")
15
+ end
16
+ end
17
+
18
+ should "retrieve defined command set if one exists" do
19
+ registry_command_called = false
20
+ PryCommandSetRegistry.define_command_set("Test", "test") do
21
+ command("test", "test") do
22
+ registry_command_called = true
23
+ end
24
+ end
25
+ run_command("import-set Test")
26
+ run_command("test")
27
+ assert_equal true, registry_command_called
28
+ end
29
+
30
+ should "favor command sets that resolve against the current binding" do
31
+ registry_command_called = false
32
+ PryCommandSetRegistry.define_command_set("Test", "test") do
33
+ command("test", "test") do
34
+ registry_command_called = true
35
+ end
36
+ end
37
+
38
+ context_command_called = false
39
+ test_set = PryCommandSetRegistry::CommandSet.new("Test", "test") do
40
+ command("test", "test") do
41
+ context_command_called = true
42
+ end
43
+ end
44
+ test_struct = Struct.new(:command_set)
45
+ test_instance = test_struct.new(test_set)
46
+ context = Pry.binding_for(test_instance)
47
+ run_command("import-set command_set", :context => context)
48
+ run_command("test")
49
+ assert_equal true, context_command_called
50
+ assert_equal false, registry_command_called
51
+ end
52
+ end
53
+
54
+ context "list-sets" do
55
+ setup do
56
+ # Reset registry
57
+ clean_registry = PryCommandSetRegistry::Registry.new
58
+ PryCommandSetRegistry.send(:registry=, clean_registry)
59
+ end
60
+
61
+ should "List no registered sets when none are registered" do
62
+ output = StringIO.new
63
+ run_command("list-sets", :output => output)
64
+ assert_equal "Registered Command Sets:\n\n", output.string
65
+ end
66
+
67
+ should "List registered sets" do
68
+ output = StringIO.new
69
+ name = "Foo"
70
+ desc = "Bar"
71
+ PryCommandSetRegistry.define_command_set(name, desc) {}
72
+ run_command("list-sets", :output => output)
73
+ expected_output = "Registered Command Sets:\n Foo - Bar\n"
74
+ assert_equal expected_output, output.string
75
+ end
76
+ end
77
+
78
+ def run_command(command, options = {})
79
+ Pry.run_command(command, options)
80
+ end
81
+ end
@@ -0,0 +1,35 @@
1
+ require "test_helper"
2
+
3
+ class PryCommandSetRegistryTest < PryCommandSetRegistry::TestCase
4
+ Subject = PryCommandSetRegistry
5
+
6
+ context Subject.name do
7
+ subject { Subject }
8
+
9
+ should "be defined" do
10
+ assert defined?(subject), "Expected #{subject.name} to be defined!"
11
+ end
12
+
13
+ should "have a registry" do
14
+ assert_kind_of PryCommandSetRegistry::Registry, Subject.registry
15
+ end
16
+
17
+ should "delegate ::command_set to ::registry" do
18
+ query = "Foo"
19
+ Subject.registry.expects(:command_set).with(query)
20
+ Subject.command_set(query)
21
+ end
22
+
23
+ should "delegate ::command_sets to ::registry" do
24
+ Subject.registry.expects(:command_sets)
25
+ Subject.command_sets
26
+ end
27
+
28
+ should "delegate ::define_command_set to ::registry" do
29
+ name = "Foo"
30
+ desc = "Bar"
31
+ Subject.registry.expects(:define_command_set).with(name, desc)
32
+ Subject.define_command_set(name, desc)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ require "test_helper"
2
+
3
+ class RegistryTest < PryCommandSetRegistry::TestCase
4
+ Subject = PryCommandSetRegistry::Registry
5
+
6
+ context "instance_methods" do
7
+ subject { Subject.new }
8
+
9
+ context "#initialize" do
10
+ should "initialize #command_sets to an empty Hash" do
11
+ assert_equal({}, subject.command_sets)
12
+ end
13
+ end
14
+
15
+ context "#define_command_set" do
16
+ should "create a new CommandSet with the given args" do
17
+ name = "foo"
18
+ description = "bar"
19
+ called = false
20
+ command_set_proc = proc { called = true }
21
+ group = subject.define_command_set(name, description, &command_set_proc)
22
+ assert_equal name, group.name
23
+ assert_equal description, group.description
24
+ assert_equal true, called, "CommandSet proc was not called!"
25
+ end
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-command-set-registry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny Guinther
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-04 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Plugin for managing registration and loading of command sets in pry.
56
+ email:
57
+ - dannyguinther@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Guardfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/pry-command-set-registry.rb
69
+ - lib/pry_command_set_registry.rb
70
+ - lib/pry_command_set_registry/command_set.rb
71
+ - lib/pry_command_set_registry/commands.rb
72
+ - lib/pry_command_set_registry/registry.rb
73
+ - lib/pry_command_set_registry/version.rb
74
+ - pry-command-set-registry.gemspec
75
+ - test/test_helper.rb
76
+ - test/unit/command_set_test.rb
77
+ - test/unit/commands_test.rb
78
+ - test/unit/pry_command_set_registry_test.rb
79
+ - test/unit/registry_test.rb
80
+ homepage: https://github.com/tdg5/pry-command-set-registry
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Plugin for managing registration and loading of command sets in pry.
104
+ test_files:
105
+ - test/test_helper.rb
106
+ - test/unit/command_set_test.rb
107
+ - test/unit/commands_test.rb
108
+ - test/unit/pry_command_set_registry_test.rb
109
+ - test/unit/registry_test.rb
110
+ has_rdoc: