switch_user 0.1.0

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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in switch_user.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Richard Huang (flyerhzm@gmail.com)
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,24 @@
1
+ switch_user
2
+ ===========
3
+
4
+ Inspired from hobo, switch_user provides a convenient way to switch current user that speed up your development.
5
+
6
+ It supports only devise now, but it will support authlogic in the future.
7
+
8
+ Install
9
+ -------
10
+
11
+ add in Gemfile.
12
+
13
+ gem "switch_user", "~> 0.1.0"
14
+
15
+ Usage
16
+ -----
17
+
18
+ add following code into your layout page.
19
+
20
+ = switch_user_select
21
+
22
+
23
+ Copyright © 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
24
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,20 @@
1
+ class SwitchUserController < ApplicationController
2
+
3
+ before_filter :developer_modes_only
4
+
5
+ def set_current_user
6
+ if params[:user_id].blank?
7
+ warden.logout(:user)
8
+ else
9
+ current_user = User.find(params[:user_id])
10
+ warden.set_user(current_user, :scope => :user)
11
+ end
12
+ redirect_to(request.env["HTTP_REFERER"] ? :back : root_path)
13
+ end
14
+
15
+ private
16
+
17
+ def developer_modes_only
18
+ render :text => "Permission Denied", :status => 403 unless Rails.env == "development"
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module SwitchUserHelper
2
+ def switch_user_select
3
+ if Rails.env == "development"
4
+ if @current_user
5
+ options = "<option value="">Guest</option>"
6
+ options += options_from_collection_for_select(User.all, :id, :email, @current_user.id)
7
+ else
8
+ options = "<option selected='selected' value="">Guest</option>"
9
+ options += options_from_collection_for_select(User.all, :id, :email)
10
+ end
11
+ select_tag "switch_user_id", options.html_safe,
12
+ :onchange => "location.href = '/switch_user?user_id=' + encodeURIComponent(this.options[this.selectedIndex].value)"
13
+ end
14
+ end
15
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ match 'switch_user' => 'switch_user#set_current_user'
3
+ end
@@ -0,0 +1,9 @@
1
+ require "rails"
2
+
3
+ module SwitchUser
4
+ class Engine < Rails::Engine
5
+ config.to_prepare do
6
+ ApplicationController.helper(SwitchUserHelper)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module SwitchUser
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/switch_user/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "switch_user"
6
+ s.version = SwitchUser::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Richard Huang"]
9
+ s.email = ["flyerhzm@gmail.com"]
10
+ s.homepage = "http://rubygems.org/gems/switch_user"
11
+ s.summary = "Easily switch current user to speed up development"
12
+ s.description = "Easily switch current user to speed up development"
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "switch_user"
16
+
17
+ s.add_development_dependency "bundler", ">= 1.0.0"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
21
+ s.require_path = 'lib'
22
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: switch_user
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Richard Huang
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-08 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Easily switch current user to speed up development
38
+ email:
39
+ - flyerhzm@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - app/controllers/switch_user_controller.rb
53
+ - app/helpers/switch_user_helper.rb
54
+ - config/routes.rb
55
+ - lib/switch_user.rb
56
+ - lib/switch_user/version.rb
57
+ - switch_user.gemspec
58
+ has_rdoc: true
59
+ homepage: http://rubygems.org/gems/switch_user
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 23
82
+ segments:
83
+ - 1
84
+ - 3
85
+ - 6
86
+ version: 1.3.6
87
+ requirements: []
88
+
89
+ rubyforge_project: switch_user
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Easily switch current user to speed up development
94
+ test_files: []
95
+