pry-command-set-registry 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bc4e47b4fe6de4fd01ea656dc1b5b30f901c2c8
4
- data.tar.gz: d117d60905175b6b40a17e7ae02b71fbd7d9d12b
3
+ metadata.gz: d66c39fac051c68eb25c6b359e765cdb9e1911ed
4
+ data.tar.gz: becc29a1efe602bcd26bdc0f915263183f5266d2
5
5
  SHA512:
6
- metadata.gz: 85515d27354c4246fda7a4b148678dd9abf0f4c4a3d91871fb5fd27fd65d31f7ecab11fbd17adea09c662bad36470cfc4a650ad47c182b8e9b55aaaaaf6938c7
7
- data.tar.gz: 984954420617368b4fad4f497573ccebdd9862756163754e1728f6f2baa309f4e485554561274885770ba341478b5f6dc1531ca9a644e4692bea1dad4f5764cb
6
+ metadata.gz: 9f8c0108a095b1d2ed833dbd1489336534f52e1880967cad7f6d711458b3d1da15c09eee34e04172d02605185bf9cdbb967102a82a0fffc97db3fc6f11f6ff9c
7
+ data.tar.gz: 66ac3d4fa32f2a9eb37129922faaf97a810b7ad555ccfb165dd2151272033624eb0c9931d32329f7f345684cbbe3183bd19b3ce33658aeb4c3ee22d46510be24
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - 2.2.0
8
+ - jruby-19mode
9
+ - jruby-head
10
+ - rbx-19mode
11
+ - rbx-2
data/Gemfile CHANGED
@@ -7,8 +7,10 @@ group :doc do
7
7
  end
8
8
 
9
9
  group :test do
10
+ gem "coveralls", :require => false
10
11
  gem "guard"
11
12
  gem "guard-minitest"
12
13
  gem "minitest", ">= 3.0"
13
14
  gem "mocha"
15
+ gem "simplecov", :require => false
14
16
  end
data/README.md CHANGED
@@ -1,29 +1,207 @@
1
1
  # PryCommandSetRegistry
2
+ [![Gem Version](https://badge.fury.io/rb/pry-command-set-registry.svg)](http://badge.fury.io/rb/pry-command-set-registry)
3
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/pry-command-set-registry)
4
+ [![Build Status](https://travis-ci.org/tdg5/pry-command-set-registry.svg)](https://travis-ci.org/tdg5/pry-command-set-registry)
5
+ [![Coverage Status](https://coveralls.io/repos/tdg5/pry-command-set-registry/badge.svg)](https://coveralls.io/r/tdg5/pry-command-set-registry)
6
+ [![Code Climate](https://codeclimate.com/github/tdg5/pry-command-set-registry/badges/gpa.svg)](https://codeclimate.com/github/tdg5/pry-command-set-registry)
7
+ [![Dependency Status](https://gemnasium.com/tdg5/pry-command-set-registry.svg)](https://gemnasium.com/tdg5/pry-command-set-registry)
2
8
 
3
- Plugin for managing registration and loading of command sets in pry.
9
+ Plugin facilitating easy definition and importation of command sets for
10
+ [Pry](https://github.com/pry/pry). Creates a central registry for command sets
4
11
 
5
12
  ## Installation
6
13
 
7
14
  Add this line to your application's Gemfile:
8
15
 
9
- gem 'pry-command-set-registry'
16
+ ```bash
17
+ gem 'pry-command-set-registry'
18
+ ```
10
19
 
11
20
  And then execute:
12
21
 
13
- $ bundle
22
+ ```bash
23
+ $ bundle
24
+ ```
14
25
 
15
26
  Or install it yourself as:
16
27
 
17
- $ gem install pry-command-set-registry
28
+ ```bash
29
+ $ gem install pry-command-set-registry
30
+ ```
18
31
 
19
32
  ## Usage
20
33
 
21
- Require library file:
34
+ `Pry` should handle loading the plugin automatically. If not, you can require the
35
+ plugin like so:
36
+
37
+ ```ruby
38
+ require "pry-command-set-registry"
39
+ ```
40
+
41
+ ### Commands and Command Set Definition
42
+
43
+ Once the plugin has been loaded you can view the commands it adds to `pry` using
44
+ the `help` command in `pry`:
45
+
46
+ ```
47
+ $ pry
48
+ [1] pry(main)> help
49
+ # ... Skipping unrelated commands ...
50
+
51
+ Command set registry
52
+ import-set Import a pry command set
53
+ list-sets List registered command sets
54
+
55
+ [2] pry(main)>
56
+ ```
57
+
58
+ The `import-set` and `list-sets` commands are the primary means of interacting
59
+ with the command set registry in `Pry`.
60
+
61
+ #### The `list-sets` command
62
+
63
+ The `list-sets` command displays a list of all registered command sets. Unless
64
+ you define your own command sets or include another library or plugin that
65
+ registers a command set, this list will be empty initially:
66
+
67
+ ```
68
+ [2] pry(main)> list-sets
69
+ Registered Command Sets:
70
+
71
+ [3] pry(main)>
72
+ ```
73
+
74
+ #### Defining a command set
75
+
76
+ Defining and registering a command set can be accomplished via the
77
+ `PryCommandSetRegistry` constant. In particular,
78
+ [`PryCommandSetRegistry.define_command_set`](http://www.rubydoc.info/gems/pry-command-set-registry/PryCommandSetRegistry.define_command_set)
79
+ provides a thin wrapper around [`Pry::CommandSet#block_command`](http://www.rubydoc.info/github/pry/pry/Pry/CommandSet:block_command)
80
+ allowing for the definition of new command sets.
81
+
82
+ Consider the following command set definition complimenting [Pry's poetic
83
+ side](https://github.com/pry/pry/blob/5e8d69e8b38b5df4c520e5faff74533c16f531a0/lib/pry/commands/easter_eggs.rb#L41)
84
+ with something a little more punk rock:
22
85
 
23
86
  ```ruby
24
- require "pry-command-set-registry"
87
+ PryCommandSetRegistry.define_command_set("PunkRock", "Pry, but more punk rock", :group => "PunkRock") do
88
+ london_calling = <<-LONDON_CALLING
89
+ --
90
+ London calling to the faraway towns
91
+ Now war is declared and battle come down
92
+
93
+ London calling to the underworld
94
+ Come out of the cupboard, you boys and girls
95
+
96
+ London calling, now don't look to us
97
+ Phony Beatlemania has bitten the dust
98
+
99
+ London calling, see we ain't got no swing
100
+ 'Cept for the ring of that truncheon thing
101
+
102
+ The ice age is coming, the sun is zooming in
103
+ Meltdown expected, the wheat is growin' thin
104
+ Engines stop running, but I have no fear
105
+ 'Cause London is drowning, and I, I live by the river
106
+
107
+ -- The Clash
108
+ LONDON_CALLING
109
+ command("london-calling", "If you have to ask then you need more help than Pry can provide") do
110
+ output.puts(london_calling)
111
+ end
112
+ end
25
113
  ```
26
114
 
115
+ If we copy and paste the above into `Pry`, we'll have defined and registered our
116
+ first command set! Once a command set has been registered, it will appear when
117
+ the `list-sets` command is invoked:
118
+
119
+ ```
120
+ [4] pry(main)> list-sets
121
+ Registered Command Sets:
122
+ PunkRock - Pry, but more punk rock
123
+
124
+ [5] pry(main)>
125
+ ```
126
+
127
+ #### The `import-set` command
128
+
129
+ To import a registered command set into the current `Pry` session, use the
130
+ `import-set` command. The `import-set` command is a [built-in `Pry` command](https://github.com/pry/pry/blob/5e8d69e8b38b5df4c520e5faff74533c16f531a0/lib/pry/commands/import_set.rb),
131
+ but it's worth noting that `PryCommandSetRegistry` overrides the default command
132
+ to include fallback behavior for retrieving command sets from the registry
133
+ [[source]](https://github.com/tdg5/pry-command-set-registry/blob/4f9914969dcfa4a826c9672bd152e12d2e7e37f6/lib/pry_command_set_registry/commands.rb#L7).
134
+ This extended behavior allows command sets to be included in a variety of
135
+ formats. For example, each of the following will all import the `PunkRock`
136
+ command set into the current `Pry` session:
137
+
138
+ ```
139
+ [5] pry(main)> import-set PunkRock
140
+ [6] pry(main)> import-set "PunkRock"
141
+ [7] pry(main)> import-set :PunkRock
142
+ ```
143
+
144
+ Even when a constant is defined with the same name as a command set, a constant
145
+ style name can still be used. This is possible because `PryCommandSetRegistry`
146
+ uses a registry that is separate from Ruby's constants. At lookup time if
147
+ `PryCommandSetRegistry` evaluates the given name as a constant, but that constant
148
+ doesn't look like a command set, it will fallback to checking the registry for a
149
+ command set with the same name. For example, ignoring the fact that we've already
150
+ imported the `PunkRock` command set three times, the following would still work
151
+ as expected:
152
+
153
+ ```
154
+ [8] pry(main)> PunkRock = "Never Mind the Bollocks"
155
+ [9] pry(main)> import-set PunkRock
156
+ ```
157
+
158
+ Now that we've imported the `PunkRock` command set, the commands it provides
159
+ will appear when the `help` command is invoked:
160
+
161
+ ```
162
+ [10] pry(main)> help
163
+ # ... Skipping unrelated commands ...
164
+ PunkRock
165
+ london-calling If you have to ask then you need more help than Pry can provide
166
+
167
+ [11] pry(main)>
168
+ ```
169
+
170
+ Finally, we can invoke the added command by name:
171
+
172
+ ```
173
+ [11] pry(main)> london-calling
174
+ --
175
+ London calling to the faraway towns
176
+ Now war is declared and battle come down
177
+
178
+ London calling to the underworld
179
+ Come out of the cupboard, you boys and girls
180
+
181
+ London calling, now don't look to us
182
+ Phony Beatlemania has bitten the dust
183
+
184
+ London calling, see we ain't got no swing
185
+ 'Cept for the ring of that truncheon thing
186
+
187
+ The ice age is coming, the sun is zooming in
188
+ Meltdown expected, the wheat is growin' thin
189
+ Engines stop running, but I have no fear
190
+ 'Cause London is drowning, and I, I live by the river
191
+
192
+ -- The Clash
193
+
194
+ [12] pry(main)>
195
+ ```
196
+
197
+ ### Pry on, dude!
198
+
199
+ That's about it for basic usage of `PryCommandSetRegistry`. Make sure to check
200
+ out the [`PryCommandSetRegistry` docs](http://www.rubydoc.info/gems/pry-command-set-registry)
201
+ for more in-depth coverage of the inner workings of `PryCommandSetRegistry`.
202
+ Also make sure to check out the excellent [page on custom commands in the
203
+ `Pry` wiki](https://github.com/pry/pry/wiki/Custom-commands)!
204
+
27
205
  ## Contributing
28
206
 
29
207
  1. Fork it ( https://github.com/tdg5/pry-command-set-registry/fork )
@@ -45,6 +45,33 @@ module PryCommandSetRegistry
45
45
  apply_group_name_to_commands
46
46
  end
47
47
 
48
+ # @overload extend(*modules)
49
+ # Adds the instance methods from each module given as a parameter to the
50
+ # command set. If both a block and modules are provided an ArgumentError
51
+ # will be raised.
52
+ # @param [Module] *modules One or more modules to extend the command set
53
+ # with.
54
+ # @return [PryCommandSetRegistry::CommandSet] Returns the command set
55
+ # object.
56
+ # @raise [ArgumentError] if called with modules and block or called with
57
+ # neither modules nor block.
58
+ # @overload extend
59
+ # Evaluates the block in the context of the command set instance. If both
60
+ # a block and arguments are provided an ArgumentError will be raised.
61
+ # @yield [] The given block is evaluated on the command set instance.
62
+ # @return [PryCommandSetRegistry::CommandSet] Returns the command set
63
+ # object.
64
+ # @raise [ArgumentError] if called with modules and block or called with
65
+ # neither modules nor block.
66
+ def extend(*modules)
67
+ if modules.any?
68
+ return super unless block_given?
69
+ raise ArgumentError, "Cannot call extend with block and modules!"
70
+ end
71
+ instance_eval(&Proc.new)
72
+ self
73
+ end
74
+
48
75
  private
49
76
 
50
77
  # If a group name was provided, adds that group to all commands in the
@@ -1,4 +1,4 @@
1
1
  module PryCommandSetRegistry
2
2
  # The version of the PryCommandSetRegistry gem.
3
- VERSION = "0.1.1".freeze
3
+ VERSION = "0.1.2".freeze
4
4
  end
@@ -1,3 +1,11 @@
1
+ if ENV["CI"]
2
+ require "simplecov"
3
+ require "coveralls"
4
+ Coveralls.wear!
5
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
6
+ SimpleCov.root(File.expand_path("../..", __FILE__))
7
+ end
8
+
1
9
  require "minitest/autorun"
2
10
  require "mocha/setup"
3
11
  require "pry_command_set_registry"
@@ -40,6 +40,47 @@ class CommandSetTest < PryCommandSetRegistry::TestCase
40
40
  assert_equal group, instance.each.first.last.group
41
41
  end
42
42
  end
43
+
44
+ context "#extend" do
45
+ subject { @subject }
46
+
47
+ setup do
48
+ @name = "Foo"
49
+ description = "Bar"
50
+ @subject = Subject.new(@name, description, &default_command_set_proc)
51
+ end
52
+
53
+ should "raise ArgumentError if neither arguments nor block are given" do
54
+ assert_raises(ArgumentError) { subject.extend }
55
+ end
56
+
57
+ should "raise ArgumentError if arguments and block are given" do
58
+ block_called = false
59
+ block = lambda { block_called = true }
60
+ dummy = Module.new
61
+ subject.expects(:instance_eval).never
62
+ assert_raises(ArgumentError) do
63
+ subject.extend(dummy, &block)
64
+ end
65
+ refute_kind_of(dummy, subject)
66
+ refute(block_called, "Expected block given to extend with arguments not to be called!")
67
+ end
68
+
69
+ should "yield to super if any arguments are given and no block given" do
70
+ dummy = Module.new
71
+ subject.expects(:instance_eval).never
72
+ result = subject.extend(dummy)
73
+ assert_kind_of(dummy, subject)
74
+ assert_equal subject, result
75
+ end
76
+
77
+ should "execute the block in the context of the command set if no arguments are given" do
78
+ receiver_in_block = nil
79
+ result = subject.extend { receiver_in_block = self }
80
+ assert_equal subject, receiver_in_block
81
+ assert_equal subject, result
82
+ end
83
+ end
43
84
  end
44
85
 
45
86
  # Proc is called with instance eval, so closure must be used to allow
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-command-set-registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Guinther
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - ".travis.yml"
63
64
  - Gemfile
64
65
  - Guardfile
65
66
  - LICENSE