younker-ssl_requirement 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in younker-ssl_requirement.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,45 @@
1
+ module Younker
2
+ module SslRequirement
3
+ def self.included(controller)
4
+ controller.extend(ClassMethods)
5
+ controller.before_filter(:ensure_proper_protocol)
6
+ end
7
+
8
+ module ClassMethods
9
+ # Specifies that the named actions requires an SSL connection to be performed (which is enforced by ensure_proper_protocol).
10
+ def ssl_required(*actions)
11
+ write_inheritable_array(:ssl_required_actions, actions)
12
+ end
13
+
14
+ def ssl_allowed(*actions)
15
+ write_inheritable_array(:ssl_allowed_actions, actions)
16
+ end
17
+ end
18
+
19
+ protected
20
+ # Returns true if the current action is supposed to run as SSL
21
+ def ssl_required?
22
+ (self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)
23
+ end
24
+
25
+ def ssl_allowed?
26
+ (self.class.read_inheritable_attribute(:ssl_allowed_actions) || []).include?(action_name.to_sym)
27
+ end
28
+
29
+ private
30
+ def ensure_proper_protocol
31
+ return true if ssl_allowed?
32
+
33
+ if ssl_required? && !request.ssl?
34
+ redirect_to "https://" + request.host + request.fullpath
35
+ flash.keep
36
+ return false
37
+ elsif request.ssl? && !ssl_required?
38
+ redirect_to "http://" + request.host + request.fullpath
39
+ flash.keep
40
+ return false
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,5 @@
1
+ module Younker
2
+ module Sslrequirement
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "younker-ssl_requirement/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "younker-ssl_requirement"
7
+ s.version = Younker::Sslrequirement::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["younker"]
10
+ s.email = ["younker@28dev.com"]
11
+ s.homepage = "http://rubygems.org/gems/younker-ssl_requirement"
12
+ s.summary = %q{SSL Requirement, forked from https://github.com/rails/ssl_requirement}
13
+ s.description = %q{See https://github.com/rails/ssl_requirement}
14
+
15
+ s.rubyforge_project = "younker-ssl_requirement"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: younker-ssl_requirement
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - younker
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-13 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: See https://github.com/rails/ssl_requirement
23
+ email:
24
+ - younker@28dev.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/younker-ssl_requirement.rb
36
+ - lib/younker-ssl_requirement/version.rb
37
+ - younker-ssl_requirement.gemspec
38
+ has_rdoc: true
39
+ homepage: http://rubygems.org/gems/younker-ssl_requirement
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: younker-ssl_requirement
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: SSL Requirement, forked from https://github.com/rails/ssl_requirement
72
+ test_files: []
73
+