absolution 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmUyY2M3NWNjNmJjNDYyNTJmOWFkMzNlMWNlMmE4ZDQzNmViNWRhNQ==
5
+ data.tar.gz: !binary |-
6
+ MGNjNjYxZmJhYWQ4ZjEwM2ZmMmZjNWIwYzJhZTNiOTIzNWFmOWQwNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NGM0ZmQ4NWVmMDUyZjM2YjRmYTJhZGFiMzI5M2M4ZDgzMTFiZmViNmI3M2Jm
10
+ MDBiYjg1ZTFhMmM0ODYxZmE1Zjc2OGYyM2JlMTNmYjQyNmExM2IwZWRjZDc1
11
+ YTdjNzVlMGUyODBjMWY2NmZhZTQwZGMyYmRlNWJjZmRiOWQxZDk=
12
+ data.tar.gz: !binary |-
13
+ YTFmNzE5MDE2MTlmM2JmMGRiNjYyZDliMGI0M2YwNzc4NjljZGNkZGE2NzUw
14
+ ZjdjOGZiMTNkN2FkMGYwZWMzNTMyOTRlYzc3NzM0ZTEyMjM1OGY4NDQ3MDg2
15
+ NDE2ZTAyODU1ODIzMmNkYWQ5MDE2YTAxMjcyZTIwYWM1MjE1ODk=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Dennis Walters
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,67 @@
1
+ ## Absolution ##
2
+
3
+ Want to know if a string is an absolute URL? Heck, want to construct an
4
+ absolute URL from a base URL and a path? This is your lucky day!
5
+
6
+ There's not much to this thing, and what's there exists only to serve the
7
+ needs that I've had for this sort of thing.
8
+
9
+ That said, pull requests are totally welcome :)
10
+
11
+ ## Gem Setup ##
12
+
13
+ ```ruby
14
+ gem install absolution
15
+
16
+ # Gemfile
17
+ gem 'absolution'
18
+ ```
19
+ ## Basic usage (class methods) ##
20
+
21
+ ```ruby
22
+ require 'absolution'
23
+
24
+ Absolution.absolute_url?('blah')
25
+ => false
26
+ Absolution.absolute_url?('/blah')
27
+ => false
28
+ Absolution.absolute_url?('http://blah')
29
+ => true
30
+
31
+ Absolution.construct_absolute_url('https://base.url', 'blah')
32
+ => 'https://base.url/blah'
33
+ ```
34
+
35
+ ## Other usage (mixin) ##
36
+
37
+ Want a class to know how to do this stuff on its own?
38
+
39
+ ```ruby
40
+ require 'absolution'
41
+
42
+ class SomeClass
43
+ include Absolution
44
+
45
+ def absolute_url_to(somefile)
46
+ return somefile if absolute_url?(somefile)
47
+ construct_absolute_url('http://base.url', somefile)
48
+ end
49
+ end
50
+ ```
51
+
52
+ ## Contributing ##
53
+
54
+ Do you use git-flow? I sure do. Please base anything you do off of
55
+ [the develop branch](https://github.com/ess/factis/tree/develop).
56
+
57
+ 1. Fork it.
58
+ 2. Perform some BDD magic. Seriously. Be testing.
59
+ 3. Submit a pull request.
60
+
61
+ ## History ##
62
+
63
+ * 0.0.2 - Initial release
64
+
65
+ ## License ##
66
+
67
+ MIT License. Copyright 2014 Dennis Walters
@@ -0,0 +1,3 @@
1
+ module Absolution
2
+ VERSION = '0.0.2'
3
+ end
data/lib/absolution.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'uri'
2
+ module Absolution
3
+
4
+ def absolute_url?(url)
5
+ scheme = URI.parse(url.to_s).scheme
6
+ !(scheme.nil? || scheme.empty?)
7
+ end
8
+
9
+ def construct_absolute_url(base_url, path)
10
+ u = URI.parse(base_url)
11
+ u.path = path.start_with?('/') ? path : "/#{path}"
12
+ u.to_s
13
+ end
14
+
15
+ extend self
16
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'absolution'
3
+
4
+ class Dummy
5
+ include Absolution
6
+ end
7
+
8
+ describe Absolution do
9
+ let(:klass) {Absolution}
10
+
11
+ context 'when included' do
12
+ let(:dummy) {Dummy.new}
13
+
14
+ it 'knows about absolute URLs' do
15
+ klass.instance_methods.each do |method|
16
+ expect(dummy).to respond_to(method)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '.absolute_url?' do
22
+
23
+ it 'is true when given a HTTP URI' do
24
+ expect(klass.absolute_url?('http://fake.url')).to be_true
25
+ end
26
+
27
+ it 'is true when given a HTTPS URI' do
28
+ expect(klass.absolute_url?('https://fake.url')).to be_true
29
+ end
30
+
31
+ it 'is false when given a schemeless path' do
32
+ expect(klass.absolute_url?('/asset.file')).to be_false
33
+ end
34
+ end
35
+
36
+ describe '.construct_absolute_url' do
37
+ it 'combines a base url with a path' do
38
+ expect(klass.construct_absolute_url('http://fake.url', '/asset.file')).
39
+ to eql('http://fake.url/asset.file')
40
+ end
41
+
42
+ it 'separates the base url from the asset with at least 1 /' do
43
+ base_url = 'http://fake.url'
44
+ asset_path = 'asset.file'
45
+ expected_url = base_url + '/' + asset_path
46
+ expect(klass.construct_absolute_url(base_url, asset_path)).
47
+ to eql(expected_url)
48
+ end
49
+
50
+ it 'removes an extra / when both the base url and the asset path have it' do
51
+ base_url = 'http://fake.url/'
52
+ asset_path = '/asset.file'
53
+ expected_url = base_url.chomp('/') + asset_path
54
+ expect(klass.construct_absolute_url(base_url, asset_path)).
55
+ to eql(expected_url)
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'rspec/mocks'
3
+ require 'rspec/expectations'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..')
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_framework = :rspec
9
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: absolution
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Walters
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Absolute URL detection and construction
28
+ email:
29
+ - dennis@elevatorup.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/absolution/version.rb
35
+ - lib/absolution.rb
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - spec/absolution_spec.rb
39
+ - spec/spec_helper.rb
40
+ homepage: http://github.com/ess/absolution
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.1.11
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Absolute URL detection and construction
64
+ test_files:
65
+ - spec/absolution_spec.rb
66
+ - spec/spec_helper.rb