earl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +48 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +5 -0
- data/earl.gemspec +19 -0
- data/lib/earl.rb +12 -0
- data/lib/earl/string_inquirer.rb +11 -0
- data/lib/earl/url.rb +78 -0
- data/lib/earl/version.rb +3 -0
- data/spec/earl/parse_spec.rb +10 -0
- data/spec/earl/parts_spec.rb +79 -0
- data/spec/earl/string_inquirer_spec.rb +17 -0
- data/spec/earl/url_spec.rb +36 -0
- data/spec/spec_helper.rb +9 -0
- metadata +82 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p125@earl"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jeremy Ruppel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Earl
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'earl'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install earl
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/earl.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/earl/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jeremy Ruppel"]
|
6
|
+
gem.email = ["jeremy.ruppel@gmail.com"]
|
7
|
+
gem.description = %q{What URI wishes it could look like}
|
8
|
+
gem.summary = %q{What URI wishes it could look like}
|
9
|
+
gem.homepage = "https://github.com/remind101/earl"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "earl"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Earl::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec', '>= 2.9.0'
|
19
|
+
end
|
data/lib/earl.rb
ADDED
data/lib/earl/url.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Earl
|
4
|
+
class URL
|
5
|
+
def initialize( source )
|
6
|
+
@uri = URI.parse( source )
|
7
|
+
end
|
8
|
+
|
9
|
+
def scheme
|
10
|
+
StringInquirer.new( parts[ :scheme ] ) rescue nil
|
11
|
+
end
|
12
|
+
def scheme=( value )
|
13
|
+
parts[ :scheme ] = value
|
14
|
+
end
|
15
|
+
def scheme?
|
16
|
+
!( parts[ :scheme ].nil? || parts[ :scheme ].empty? )
|
17
|
+
end
|
18
|
+
|
19
|
+
def subdomain
|
20
|
+
StringInquirer.new( parts[ :subdomain ] ) rescue nil
|
21
|
+
end
|
22
|
+
def subdomain=( value )
|
23
|
+
parts[ :subdomain ] = value
|
24
|
+
end
|
25
|
+
def subdomain?
|
26
|
+
!( parts[ :subdomain ].nil? || parts[ :subdomain ].empty? )
|
27
|
+
end
|
28
|
+
|
29
|
+
def host
|
30
|
+
StringInquirer.new( [ domain, top_level_domain ].compact.join( '.' ) ) rescue nil
|
31
|
+
end
|
32
|
+
def host=( value )
|
33
|
+
parts[ :domain ], parts[ :top_level_domain ] = value.split( '.' )
|
34
|
+
end
|
35
|
+
def host?
|
36
|
+
[ domain, top_level_domain ].compact.any?
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
out = ''
|
41
|
+
out << "#{scheme}://" if scheme?
|
42
|
+
out << [ subdomain, domain, top_level_domain ].compact.join( '.' )
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def domain
|
48
|
+
StringInquirer.new( parts[ :domain ] ) rescue nil
|
49
|
+
end
|
50
|
+
def top_level_domain
|
51
|
+
StringInquirer.new( parts[ :top_level_domain ] ) rescue nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def parts
|
55
|
+
@parts ||= begin
|
56
|
+
{ }.tap do |hsh|
|
57
|
+
hsh[ :scheme ] = @uri.scheme
|
58
|
+
hsh[ :subdomain ], hsh[ :domain ], hsh[ :top_level_domain ] = domain_parts
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def domain_parts
|
64
|
+
parts = host_parts || [ nil ]
|
65
|
+
parts << nil if parts.size == 1
|
66
|
+
parts.unshift nil if parts.size == 2
|
67
|
+
parts
|
68
|
+
end
|
69
|
+
|
70
|
+
def host_parts
|
71
|
+
if @uri.host
|
72
|
+
@uri.host.split '.'
|
73
|
+
elsif @uri.path
|
74
|
+
@uri.path.split '.'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/earl/version.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Earl::URL do
|
4
|
+
|
5
|
+
describe '#scheme' do
|
6
|
+
context 'when provided' do
|
7
|
+
subject { Earl::URL.new 'http://www.foo.com' }
|
8
|
+
its( :scheme ){ should eq( 'http' ) }
|
9
|
+
its( :scheme? ){ should be_true }
|
10
|
+
|
11
|
+
it 'should be settable' do
|
12
|
+
subject.scheme = 'https'
|
13
|
+
subject.scheme.should eq( 'https' )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when not provided' do
|
18
|
+
subject { Earl::URL.new 'www.foo.com' }
|
19
|
+
its( :scheme ){ should eq( nil ) }
|
20
|
+
its( :scheme? ){ should be_false }
|
21
|
+
|
22
|
+
it 'should be settable' do
|
23
|
+
subject.scheme = 'https'
|
24
|
+
subject.scheme.should eq( 'https' )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#domain' do
|
30
|
+
pending
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#subdomain' do
|
34
|
+
context 'when provided' do
|
35
|
+
subject { Earl::URL.new 'http://www.foo.com' }
|
36
|
+
its( :subdomain ){ should eq( 'www' ) }
|
37
|
+
its( :subdomain? ){ should be_true }
|
38
|
+
|
39
|
+
it 'should be settable' do
|
40
|
+
subject.subdomain = 'secure'
|
41
|
+
subject.subdomain.should eq( 'secure' )
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when not provided' do
|
46
|
+
subject { Earl::URL.new 'foo.com' }
|
47
|
+
its( :subdomain ){ should eq( nil ) }
|
48
|
+
its( :subdomain? ){ should be_false }
|
49
|
+
|
50
|
+
it 'should be settable' do
|
51
|
+
subject.subdomain = 'secure'
|
52
|
+
subject.subdomain.should eq( 'secure' )
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#host' do
|
58
|
+
context 'when provided' do
|
59
|
+
subject { Earl::URL.new 'http://www.foo.com' }
|
60
|
+
its( :host ){ should eq( 'foo.com' ) }
|
61
|
+
its( :host? ){ should be_true }
|
62
|
+
|
63
|
+
it 'should be settable' do
|
64
|
+
subject.host = 'bar.com'
|
65
|
+
subject.host.should eq( 'bar.com' )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when not provided' do
|
70
|
+
it 'should raise an error' do
|
71
|
+
expect { Earl::URL.new 'http://' }.to raise_error( URI::InvalidURIError )
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#path' do
|
77
|
+
pending
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Earl::StringInquirer do
|
4
|
+
subject { Earl::StringInquirer.new 'foo' }
|
5
|
+
|
6
|
+
it { should be_a( String ) }
|
7
|
+
its( :foo? ){ should be_true }
|
8
|
+
its( :bar? ){ should be_false }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Earl::URL do
|
12
|
+
subject { Earl::URL.new 'http://www.foo.com' }
|
13
|
+
|
14
|
+
its( :scheme ){ should be_a( Earl::StringInquirer ) }
|
15
|
+
its( :subdomain ){ should be_a( Earl::StringInquirer ) }
|
16
|
+
its( :host ){ should be_a( Earl::StringInquirer ) }
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Earl::URL do
|
4
|
+
|
5
|
+
it 'should be able to change the scheme' do
|
6
|
+
url = Earl::URL.new 'http://foo.com'
|
7
|
+
url.scheme = 'https'
|
8
|
+
url.to_s.should eq( 'https://foo.com' )
|
9
|
+
end
|
10
|
+
it 'should be able to add a scheme' do
|
11
|
+
url = Earl::URL.new 'foo.com'
|
12
|
+
url.scheme = 'http'
|
13
|
+
url.to_s.should eq( 'http://foo.com' )
|
14
|
+
end
|
15
|
+
it 'should be able to remove the scheme' do
|
16
|
+
url = Earl::URL.new 'http://foo.com'
|
17
|
+
url.scheme = nil
|
18
|
+
url.to_s.should eq( 'foo.com' )
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should be able to change the subdomain' do
|
22
|
+
url = Earl::URL.new 'foo.bar.com'
|
23
|
+
url.subdomain = 'baz'
|
24
|
+
url.to_s.should eq( 'baz.bar.com' )
|
25
|
+
end
|
26
|
+
it 'should be able to add a subdomain' do
|
27
|
+
url = Earl::URL.new 'foo.com'
|
28
|
+
url.subdomain = 'bar'
|
29
|
+
url.to_s.should eq( 'bar.foo.com' )
|
30
|
+
end
|
31
|
+
it 'should be able to remove the subdomain' do
|
32
|
+
url = Earl::URL.new 'foo.bar.com'
|
33
|
+
url.subdomain = nil
|
34
|
+
url.to_s.should eq( 'bar.com' )
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: earl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeremy Ruppel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-13 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: 2.9.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: 2.9.0
|
30
|
+
description: What URI wishes it could look like
|
31
|
+
email:
|
32
|
+
- jeremy.ruppel@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rvmrc
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- earl.gemspec
|
44
|
+
- lib/earl.rb
|
45
|
+
- lib/earl/string_inquirer.rb
|
46
|
+
- lib/earl/url.rb
|
47
|
+
- lib/earl/version.rb
|
48
|
+
- spec/earl/parse_spec.rb
|
49
|
+
- spec/earl/parts_spec.rb
|
50
|
+
- spec/earl/string_inquirer_spec.rb
|
51
|
+
- spec/earl/url_spec.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
homepage: https://github.com/remind101/earl
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.19
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: What URI wishes it could look like
|
77
|
+
test_files:
|
78
|
+
- spec/earl/parse_spec.rb
|
79
|
+
- spec/earl/parts_spec.rb
|
80
|
+
- spec/earl/string_inquirer_spec.rb
|
81
|
+
- spec/earl/url_spec.rb
|
82
|
+
- spec/spec_helper.rb
|