Skip to content

Commit

Permalink
Add command for rails console
Browse files Browse the repository at this point in the history
Add command `show_unused_views` for irb
Add command `show-unused-views` for pry
  • Loading branch information
ToQoz committed Dec 25, 2012
1 parent e87d796 commit ada5e64
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -7,6 +7,7 @@ gemspec

# jquery-rails is used by the dummy application
gem "jquery-rails"
gem 'pry-rails', :git => 'git://github.com/rweng/pry-rails.git'

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
Expand Down
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,24 @@ $ bundle exec rake 'unused_views[users]'

```

or start `rails console` and excute command.

```sh
$ bundle exec rails console
irb(main):001:0> show_unused_views
/Users/toqoz/Projects/ppp/app/views/articles/edit.html.erb
/Users/toqoz/Projects/ppp/app/views/articles/new.html.erb
/Users/toqoz/Projects/ppp/app/views/users/create.html.erb
/Users/toqoz/Projects/ppp/app/views/users/edit.html.erb

# if you use pry-rails
[1] pry(main)> show-unused-views
/Users/toqoz/Projects/ppp/app/views/articles/edit.html.erb
/Users/toqoz/Projects/ppp/app/views/articles/new.html.erb
/Users/toqoz/Projects/ppp/app/views/users/create.html.erb
/Users/toqoz/Projects/ppp/app/views/users/edit.html.erb
```

then see list of unused views.

Now this is not support partial view.
7 changes: 7 additions & 0 deletions lib/unused_view/commands.rb
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-

require 'console_command'
command_glob = File.expand_path('../commands/*.rb', __FILE__)
Dir[command_glob].each do |command|
require command
end
17 changes: 17 additions & 0 deletions lib/unused_view/commands/show_unused_views.rb
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

CC.define_command('show-unused-views') do |c|
c.description "Show unused views list"
c.group "UnusedView"
c.options do |opts|
opt.banner unindent <<-USAGE
Usage: show-unused-views [PATH]
Show unused views list
USAGE
end
c.process do
Rails.application.eager_load!
puts UnusedView.find_all(Rails.root.join('app').join('views'))
end
end
4 changes: 4 additions & 0 deletions lib/unused_view/railtie.rb
Expand Up @@ -3,5 +3,9 @@ class Railtie < Rails::Railtie
rake_tasks do
load "unused_view/tasks.rake"
end

console do
require "unused_view/commands"
end
end
end
2 changes: 1 addition & 1 deletion lib/unused_view/version.rb
@@ -1,3 +1,3 @@
module UnusedView
VERSION = "0.0.1"
VERSION = "0.0.2"
end
1 change: 1 addition & 0 deletions unused_view.gemspec
Expand Up @@ -16,6 +16,7 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]

s.add_dependency "rails", ">= 3.2"
s.add_dependency "console_command", ">= 0.0.2"
s.add_development_dependency "sqlite3"
s.add_development_dependency "rspec-rails"
end

0 comments on commit ada5e64

Please sign in to comment.