console_command 0.0.2
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.
- data/MIT-LICENSE +20 -0
- data/README.md +56 -0
- data/Rakefile +27 -0
- data/lib/console_command.rb +11 -0
- data/lib/console_command/command.rb +63 -0
- data/lib/console_command/railtie.rb +13 -0
- data/lib/console_command/version.rb +3 -0
- data/lib/tasks/console_command_tasks.rake +4 -0
- metadata +109 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Takatoshi Matsumoto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
# ConsoleCommand
|
3
|
+
|
4
|
+
This Rails plugin is enable to add command easily to `rails console` even if it is using which of pry and irb.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
In your Gemfile.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
group :development do
|
12
|
+
gem "console_command"
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
and puts ruby script as follows in `config/console_command/`. Some examples are in [examples/](https://github.com/ToQoz/console_command/tree/master/examples)
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# config/console_command/what_time_is_it_now.rb
|
20
|
+
# CC aliased to ConsoleCommand
|
21
|
+
CC.define_command('what-time-is-it-now') do |c|
|
22
|
+
c.description "display current time" # this infomation is used only by pry
|
23
|
+
c.group "Joke" # this infomation is used only by pry
|
24
|
+
c.options do |opts| # this infomation is used only by pry
|
25
|
+
opt.banner unindent <<-USAGE
|
26
|
+
Usage: what-time-is-it-now
|
27
|
+
|
28
|
+
display what-time-is-it-now
|
29
|
+
USAGE
|
30
|
+
end
|
31
|
+
c.process do
|
32
|
+
puts Time.now
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
and start rails console and execute command.
|
38
|
+
|
39
|
+
**If you use irb for `rails console`, hyphen in command name is automatically converted to underscore.** Because we can't use hyphen for command name in irb
|
40
|
+
|
41
|
+
```sh
|
42
|
+
# with pry
|
43
|
+
$ rails console
|
44
|
+
[1] pry(main)> what-time-is-it-now
|
45
|
+
2012-12-22 17:26:26 +0900
|
46
|
+
[2] pry(main)> help
|
47
|
+
...
|
48
|
+
Joke
|
49
|
+
what-time-is-it-now display current time
|
50
|
+
...
|
51
|
+
|
52
|
+
# with irb
|
53
|
+
$ rails console
|
54
|
+
irb(main):001:0> what_time_is_it_now
|
55
|
+
2012-12-22 17:26:26 +0900
|
56
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ConsoleCommand'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module ConsoleCommand
|
4
|
+
class Command
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def define_command(name)
|
8
|
+
command = new(name.to_s)
|
9
|
+
yield command
|
10
|
+
command.add_to_irb_command
|
11
|
+
command.add_to_pry_command if defined? Pry
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
[ :name, :description, :group, :options, :process ].each do |name|
|
16
|
+
define_method(name) do |value = nil, &block|
|
17
|
+
if value
|
18
|
+
instance_variable_set "@#{name}", value
|
19
|
+
elsif block
|
20
|
+
instance_variable_set "@#{name}", block
|
21
|
+
else
|
22
|
+
attrribute = instance_variable_get "@#{name}"
|
23
|
+
attrribute.respond_to?(:call) ? attrribute.call : attrribute
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(name)
|
29
|
+
@name = name
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_to_pry_command
|
33
|
+
command = self
|
34
|
+
command_sets = Pry::CommandSet.new
|
35
|
+
command_sets.create_command(name) do
|
36
|
+
group command.group
|
37
|
+
description command.description
|
38
|
+
define_method(:process) do
|
39
|
+
command.process
|
40
|
+
end
|
41
|
+
define_method(:options) do |opts|
|
42
|
+
command.options opts
|
43
|
+
end
|
44
|
+
end
|
45
|
+
Pry.commands.import command_sets
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_to_irb_command
|
49
|
+
require 'irb'
|
50
|
+
require 'irb/cmd/nop'
|
51
|
+
command = self
|
52
|
+
command_class = Class.new IRB::ExtendCommand::Nop do
|
53
|
+
define_method :execute do
|
54
|
+
command.process
|
55
|
+
end
|
56
|
+
end
|
57
|
+
irb_cmd_name = name.gsub('-', '_')
|
58
|
+
class_name = irb_cmd_name.to_s.classify
|
59
|
+
IRB::ExtendCommand.const_set class_name, command_class
|
60
|
+
IRB::ExtendCommandBundle.def_extend_command irb_cmd_name, class_name
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: console_command
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Takatoshi Matsumoto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.2'
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
type: :development
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
name: sqlite3
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
type: :development
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
name: rspec-rails
|
55
|
+
prerelease: false
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: This Rails plugin is enable to add command easily to `rails console`
|
63
|
+
even if it is using which of pry and irb
|
64
|
+
email:
|
65
|
+
- toqoz403@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- lib/console_command/command.rb
|
71
|
+
- lib/console_command/railtie.rb
|
72
|
+
- lib/console_command/version.rb
|
73
|
+
- lib/console_command.rb
|
74
|
+
- lib/tasks/console_command_tasks.rake
|
75
|
+
- MIT-LICENSE
|
76
|
+
- Rakefile
|
77
|
+
- README.md
|
78
|
+
homepage: http://github.com/ToQoz/console_command
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
hash: -446349457083776481
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: -446349457083776481
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.24
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: This is Rails plugin provides DSL for adding command in `rails console` (pry
|
108
|
+
and irb.)
|
109
|
+
test_files: []
|