protocool 0.0.1
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/LICENSE +21 -0
- data/README.md +31 -0
- data/lib/protocool/version.rb +9 -0
- data/lib/protocool.rb +16 -0
- data/spec/lib/protocool_spec.rb +28 -0
- data/spec/spec_helper.rb +25 -0
- metadata +104 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013 Bukowskis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Protocool
|
2
|
+
|
3
|
+
Decides whether to use TLS encryption or not on a per-environment basis in Rails. Inspired by [this discussion](http://stackoverflow.com/questions/3634100/rails-3-ssl-deprecation).
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install protocool
|
9
|
+
````
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
|
13
|
+
#### Syntax
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# In development mode:
|
17
|
+
Protcool.https # => 'http'
|
18
|
+
|
19
|
+
# In any other environment:
|
20
|
+
Protcool.https # => 'https'
|
21
|
+
````
|
22
|
+
|
23
|
+
#### Examples
|
24
|
+
|
25
|
+
In your routes:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
scope constraints: { protocol: "#{Protocool.https}://" } do
|
29
|
+
# ...
|
30
|
+
end
|
31
|
+
```
|
data/lib/protocool.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
module Protocool
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def https
|
6
|
+
use_ssl? ? 'https' : 'http'
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def use_ssl?
|
12
|
+
# *Possibly* add "test environment" as an exception as well.
|
13
|
+
# But staging and production must really have SSL!
|
14
|
+
!Rails.env.development?
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Protocool do
|
4
|
+
|
5
|
+
let(:dev_env) { mock(:environment, development?: true) }
|
6
|
+
let(:another_env) { mock(:environment, development?: false) }
|
7
|
+
let(:protocool) { Protocool }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Rails.stub!(:env).and_return another_env
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.https' do
|
14
|
+
it 'uses HTTPS by default' do
|
15
|
+
protocool.https.should == 'https'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'in development environment' do
|
20
|
+
describe '.https' do
|
21
|
+
it 'uses HTTP' do
|
22
|
+
Rails.stub!(:env).and_return dev_env
|
23
|
+
protocool.https.should == 'http'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'protocool'
|
2
|
+
|
3
|
+
def ensure_class_or_module(full_name, class_or_module)
|
4
|
+
full_name.to_s.split(/::/).inject(Object) do |context, name|
|
5
|
+
begin
|
6
|
+
context.const_get(name)
|
7
|
+
rescue NameError
|
8
|
+
if class_or_module == :class
|
9
|
+
context.const_set(name, Class.new)
|
10
|
+
else
|
11
|
+
context.const_set(name, Module.new)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def ensure_module(name)
|
18
|
+
ensure_class_or_module(name, :module)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ensure_class(name)
|
22
|
+
ensure_class_or_module(name, :class)
|
23
|
+
end
|
24
|
+
|
25
|
+
ensure_module :Rails
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: protocool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- bukowskis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: guard-rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rb-fsevent
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Decides whether to use TLS encryption or not on a per-environment basis
|
63
|
+
in Rails. Usually people don't have SSL on their local development machines, this
|
64
|
+
gem makes it a configuration less no-brainer to enforce SSL everywhere else.
|
65
|
+
email:
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- lib/protocool/version.rb
|
71
|
+
- lib/protocool.rb
|
72
|
+
- spec/lib/protocool_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- README.md
|
75
|
+
- LICENSE
|
76
|
+
homepage: https://github.com/bukowskis/protocool
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --encoding
|
82
|
+
- UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.23
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Decides whether to use TLS encryption or not on a per-environment basis in
|
103
|
+
Rails.
|
104
|
+
test_files: []
|