rails-sh 1.1.3 → 1.1.4

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/README.rdoc CHANGED
@@ -48,6 +48,8 @@ Print routes:
48
48
 
49
49
  please type help
50
50
 
51
+ == TODO
52
+
51
53
  == Contributing to rails-sh
52
54
 
53
55
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3
1
+ 1.1.4
data/lib/rails/sh.rb CHANGED
@@ -1,6 +1,7 @@
1
- require 'rails/sh/command'
2
- require 'rails/sh/patch_for_kernel'
3
1
  require 'readline'
2
+ require 'rails/sh/patch_for_kernel'
3
+ require 'rails/sh/command'
4
+ require 'rails/sh/commands'
4
5
 
5
6
  module Rails
6
7
  module Sh
@@ -12,13 +13,15 @@ module Rails
12
13
  puts "Rails.env: #{Rails.env}"
13
14
  puts "type `help` to print help"
14
15
  setup_readline
15
- while buf = Readline.readline("\e[42mrails>\e[0m ", true)
16
+ while buf = Readline.readline("rails> ", true)
16
17
  line = buf.strip
17
18
  next if line.empty?
18
19
  begin
19
20
  execute(line)
20
- rescue => e
21
- puts "\e[41m#{e.message}\e[0m"
21
+ rescue SystemExit
22
+ raise
23
+ rescue Exception => e
24
+ puts "\e[41m#{e.message}\n#{e.backtrace.join("\n")}\e[0m"
22
25
  end
23
26
  setup_readline
24
27
  end
@@ -33,7 +36,7 @@ module Rails
33
36
 
34
37
  def execute(line)
35
38
  if command = Command.find(line)
36
- arg = line[/\s+[^\s]+/].strip rescue nil
39
+ arg = line.split(/\s+/, 2)[1] rescue nil
37
40
  command.call(arg)
38
41
  else
39
42
  execute_rails_command(line)
@@ -11,7 +11,7 @@ module Rails
11
11
  end
12
12
 
13
13
  def find(line)
14
- if name = line[/\w+/]
14
+ if name = line.split(/\s+/, 2)[0]
15
15
  commands[name.to_sym]
16
16
  else
17
17
  nil
@@ -21,55 +21,11 @@ module Rails
21
21
  def command_names
22
22
  commands.keys
23
23
  end
24
+
25
+ def [](name)
26
+ commands[name]
27
+ end
24
28
  end
25
29
  end
26
30
  end
27
- end
28
-
29
- module Kernel
30
- alias_method :_exit, :exit
31
- def exit(*args); end
32
- end
33
-
34
- Rails::Sh::Command.define 'help' do
35
- Rails::Sh.execute_rails_command('--help')
36
- puts <<HELP
37
-
38
- The rails-sh commands are:
39
- help print help
40
- routes CONTROLLER print routes
41
- exit exit from rails-sh
42
- HELP
43
- end
44
-
45
- Rails::Sh::Command.define 'routes' do |controller|
46
- Rails.application.reload_routes!
47
- all_routes = Rails.application.routes.routes
48
-
49
- if controller.present?
50
- all_routes = all_routes.select{ |route| route.defaults[:controller] == controller }
51
- end
52
-
53
- routes = all_routes.collect do |route|
54
-
55
- reqs = route.requirements.dup
56
- reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
57
- reqs = reqs.empty? ? "" : reqs.inspect
58
-
59
- {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
60
- end
61
-
62
- routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route
63
-
64
- name_width = routes.map{ |r| r[:name].length }.max
65
- verb_width = routes.map{ |r| r[:verb].length }.max
66
- path_width = routes.map{ |r| r[:path].length }.max
67
-
68
- routes.each do |r|
69
- puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
70
- end
71
- end
72
-
73
- Rails::Sh::Command.define 'exit' do
74
- _exit
75
31
  end
@@ -0,0 +1,69 @@
1
+ module Kernel
2
+ alias_method :_exit, :exit
3
+ def exit(*args); end
4
+ end
5
+
6
+ include Rails::Sh
7
+
8
+ Command.define 'help' do
9
+ execute_rails_command('--help')
10
+ puts <<HELP
11
+
12
+ \e[36mThe rails-sh commands are:
13
+ help print help
14
+ routes CONTROLLER print routes
15
+ exit exit from rails-sh
16
+ restart restart rails-sh
17
+ system execute a system command
18
+ eval eval as ruby script\e[0m
19
+ HELP
20
+ end
21
+
22
+ Command.define 'routes' do |controller|
23
+ Rails.application.reload_routes!
24
+ all_routes = Rails.application.routes.routes
25
+
26
+ if controller.present?
27
+ all_routes = all_routes.select{ |route| route.defaults[:controller] == controller }
28
+ end
29
+
30
+ routes = all_routes.collect do |route|
31
+
32
+ reqs = route.requirements.dup
33
+ reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
34
+ reqs = reqs.empty? ? "" : reqs.inspect
35
+
36
+ {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
37
+ end
38
+
39
+ routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route
40
+
41
+ name_width = routes.map{ |r| r[:name].length }.max
42
+ verb_width = routes.map{ |r| r[:verb].length }.max
43
+ path_width = routes.map{ |r| r[:path].length }.max
44
+
45
+ routes.each do |r|
46
+ puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
47
+ end
48
+ end
49
+
50
+ Command.define 'system' do |arg|
51
+ system arg
52
+ end
53
+
54
+ Command.define '!' do |arg|
55
+ Command[:system].call(arg)
56
+ end
57
+
58
+ Command.define 'eval' do |arg|
59
+ puts "\e[34m=> #{eval(arg, binding, __FILE__, __LINE__).inspect}\e[0m"
60
+ end
61
+
62
+ Command.define 'restart' do
63
+ puts 'restarting...'
64
+ exec File.expand_path($0)
65
+ end
66
+
67
+ Command.define 'exit' do
68
+ _exit
69
+ end
data/rails-sh.gemspec ADDED
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rails-sh}
8
+ s.version = "1.1.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jugyo"]
12
+ s.date = %q{2011-01-31}
13
+ s.default_executable = %q{rails-sh}
14
+ s.description = %q{The Rails Shell to execute sub commands of rails quickly.}
15
+ s.email = %q{jugyo.org@gmail.com}
16
+ s.executables = ["rails-sh"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/rails-sh",
31
+ "lib/rails/sh.rb",
32
+ "lib/rails/sh/command.rb",
33
+ "lib/rails/sh/commands.rb",
34
+ "lib/rails/sh/patch_for_kernel.rb",
35
+ "rails-sh.gemspec",
36
+ "spec/rails/sh/command_spec.rb",
37
+ "spec/rails/sh_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/jugyo/rails-sh}
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.7}
44
+ s.summary = %q{The Rails Shell}
45
+ s.test_files = [
46
+ "spec/rails/sh/command_spec.rb",
47
+ "spec/rails/sh_spec.rb",
48
+ "spec/spec_helper.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
57
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_development_dependency(%q<rcov>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ end
72
+ end
73
+
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rails::Sh::Command do
4
+ before do
5
+ Rails::Sh::Command.commands.clear
6
+ end
7
+
4
8
  context 'when define a command' do
5
9
  before do
6
10
  @block = lambda {}
@@ -16,7 +20,13 @@ describe Rails::Sh::Command do
16
20
  end
17
21
 
18
22
  it 'We can get command names' do
19
- Rails::Sh::Command.command_names.should =~ [:exit, :foo, :help, :routes]
23
+ Rails::Sh::Command.command_names.should =~ [:foo]
24
+ end
25
+
26
+ define 'Command.[]' do
27
+ it 'can get a command' do
28
+ Rails::Sh::Command['foo'].should eq(@block)
29
+ end
20
30
  end
21
31
  end
22
32
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 3
9
- version: 1.1.3
8
+ - 4
9
+ version: 1.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - jugyo
@@ -96,7 +96,9 @@ files:
96
96
  - bin/rails-sh
97
97
  - lib/rails/sh.rb
98
98
  - lib/rails/sh/command.rb
99
+ - lib/rails/sh/commands.rb
99
100
  - lib/rails/sh/patch_for_kernel.rb
101
+ - rails-sh.gemspec
100
102
  - spec/rails/sh/command_spec.rb
101
103
  - spec/rails/sh_spec.rb
102
104
  - spec/spec_helper.rb
@@ -114,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
116
  requirements:
115
117
  - - ">="
116
118
  - !ruby/object:Gem::Version
117
- hash: -4011070128636660767
119
+ hash: 2507523378903183638
118
120
  segments:
119
121
  - 0
120
122
  version: "0"