sinatra-presence 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +5 -0
- data/lib/sinatra/presence.rb +9 -3
- data/lib/sinatra/presence/version.rb +1 -1
- data/sinatra-presence.gemspec +2 -0
- data/spec/app/test_app.rb +1 -1
- data/spec/extension_spec.rb +14 -1
- data/spec/spec_helper.rb +17 -9
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d8bc39da61b0cde6281d284e48a6890b912ea4
|
4
|
+
data.tar.gz: fc7c9f7c761e58d19994edd3a1de6af953b87613
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aa341df0159620fab1fdd24d53bc0bd6b2c012f29db987ab6f672135a9fd61276acd87f598905e81a03ab440fbd96c0eee48ab798cc1d1eb22e9267e8140e22
|
7
|
+
data.tar.gz: af053b91468b63ebe02b0277022b35097f1994060fa9277cb1f0763a3f6f1a921995e2f64004fbac952b58a44812b65d9e1953d933047ecf49be2ade5ed7dccc
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -27,6 +27,11 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
Register like a typical Sinatra extension
|
29
29
|
|
30
|
+
Set a local setting for local_authority in your sinatra app.rb (or config.rb or however you do it).
|
31
|
+
Include everything from the scheme to the port that will get replaced.
|
32
|
+
|
33
|
+
set :local_authority, 'http://192.168.0.1:8080'
|
34
|
+
|
30
35
|
## Contributing
|
31
36
|
|
32
37
|
1. Fork it ( https://github.com/pfarrell/presence/fork )
|
data/lib/sinatra/presence.rb
CHANGED
@@ -4,11 +4,17 @@ module Sinatra
|
|
4
4
|
module Presence
|
5
5
|
|
6
6
|
def self.registered(app)
|
7
|
-
app.set :local_authority, '127.0.0.1:9292' # http://en.wikipedia.org/wiki/URI_scheme
|
7
|
+
app.set :local_authority, 'http://127.0.0.1:9292' # http://en.wikipedia.org/wiki/URI_scheme
|
8
|
+
|
9
|
+
app.before do
|
10
|
+
if(request.cookies["local_url"].nil?)
|
11
|
+
new_url = request.url.gsub("#{request.scheme}://#{request.host_with_port}", "#{settings.local_authority}").gsub("/local", "")
|
12
|
+
response.set_cookie(:local_url, value: new_url, expires: Time.now + 600)
|
13
|
+
end
|
14
|
+
end
|
8
15
|
|
9
16
|
app.get '/local' do
|
10
|
-
new_url = request.url.gsub("#{request.host_with_port}", "#{settings.local_authority}")
|
11
|
-
.gsub("/local", "")
|
17
|
+
new_url = request.url.gsub("#{request.host_with_port}", "#{settings.local_authority}").gsub("/local", "")
|
12
18
|
redirect to(new_url)
|
13
19
|
end
|
14
20
|
end
|
data/sinatra-presence.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake", "~> 10.3"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.1"
|
26
26
|
spec.add_development_dependency "rack-test", "~> 0.6"
|
27
|
+
spec.add_development_dependency "simplecov"
|
28
|
+
spec.add_development_dependency "byebug"
|
27
29
|
end
|
data/spec/app/test_app.rb
CHANGED
data/spec/extension_spec.rb
CHANGED
@@ -2,7 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Sinatra::Presence do
|
4
4
|
it "should initialize with :local_authority set to 127.0.0.1" do
|
5
|
-
expect(TestApp.local_authority).to eq('127.0.0.1:9292')
|
5
|
+
expect(TestApp.local_authority).to eq('http://127.0.0.1:9292')
|
6
|
+
end
|
7
|
+
|
8
|
+
# validate rack-test is working
|
9
|
+
it "should respond to '/'" do
|
10
|
+
get '/'
|
11
|
+
expect(last_response.body).to eq("Hellocal")
|
6
12
|
end
|
7
13
|
|
8
14
|
it "should respond to '/local'" do
|
@@ -13,4 +19,11 @@ describe Sinatra::Presence do
|
|
13
19
|
get '/local'
|
14
20
|
expect(last_response).to be_redirect
|
15
21
|
end
|
22
|
+
|
23
|
+
it "should set a cookie" do
|
24
|
+
get '/'
|
25
|
+
expect(rack_mock_session.cookie_jar["local_url"]).to eq("http://127.0.0.1:9292/")
|
26
|
+
end
|
27
|
+
|
16
28
|
end
|
29
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -2,24 +2,32 @@ require 'rubygems'
|
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'rspec'
|
4
4
|
require 'rack/test'
|
5
|
+
require 'simplecov'
|
5
6
|
|
6
7
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'sinatra', 'presence')
|
7
8
|
require File.join(File.dirname(__FILE__), 'app', 'test_app')
|
8
9
|
|
10
|
+
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter "vendor"
|
13
|
+
end
|
14
|
+
|
15
|
+
ENV['RACK_ENV'] = 'test'
|
16
|
+
|
9
17
|
RSpec.configure do |config|
|
10
|
-
|
11
|
-
config.expect_with :rspec do |expectations|
|
12
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
13
|
-
end
|
18
|
+
begin
|
19
|
+
# config.expect_with :rspec do |expectations|
|
20
|
+
# expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
21
|
+
# end
|
14
22
|
|
15
|
-
config.mock_with :rspec do |mocks|
|
16
|
-
mocks.verify_partial_doubles = true
|
17
|
-
end
|
23
|
+
# config.mock_with :rspec do |mocks|
|
24
|
+
# mocks.verify_partial_doubles = true
|
25
|
+
# end
|
18
26
|
|
19
27
|
begin
|
20
28
|
config.filter_run :focus
|
21
29
|
config.run_all_when_everything_filtered = true
|
22
|
-
config.disable_monkey_patching!
|
30
|
+
#config.disable_monkey_patching!
|
23
31
|
config.warnings = true
|
24
32
|
if config.files_to_run.one?
|
25
33
|
config.default_formatter = 'doc'
|
@@ -31,7 +39,7 @@ RSpec.configure do |config|
|
|
31
39
|
|
32
40
|
Kernel.srand config.seed
|
33
41
|
end
|
34
|
-
|
42
|
+
end
|
35
43
|
def app
|
36
44
|
@app ||= ::Rack::Builder.new do
|
37
45
|
run ::TestApp
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-presence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Farrell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: |-
|
84
112
|
Sinatra extension for allowing an application to auto-redirect to
|
85
113
|
to a local ip address when it's possible.
|