rschenk-simple_uri_template 0.1.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ryan Schenk
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.rdoc ADDED
@@ -0,0 +1,70 @@
1
+ = simple_uri_template
2
+
3
+ * http://github.com/rschenk/simple_uri_template
4
+
5
+ == DESCRIPTION:
6
+
7
+ Simple URI Template is a ridiculously simple URI Templating class.
8
+
9
+ It does not support all of the features of URI Templating (http://bitworking.org/projects/URI-Templates/) but it does support the simplest case well.
10
+
11
+ I created it because the two Ruby URI Template libraries I could find (http://github.com/sporkmonger/addressable and https://rubyforge.org/projects/uri-template/) were making my life more difficult than necessary. Both libraries required String values for both keys and values in the "expansion" Hash. How annoying.
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * Allows both Strings and Symbols as expansion Hash keys
16
+ * Allows any object that responds to to_s as expansion values
17
+ * Consists of one gsub
18
+ * Only the simplest case of URI Templates, not all that fancy join stuff
19
+
20
+ == SYNOPSIS:
21
+
22
+ template = SimpleURITemplate.new "http://github.com/{user}/{project}"
23
+
24
+ template.expand { :user => 'rschenk', :project => 'simple_uri_template' }
25
+ #=> "http://github.com/rschenk/simple_uri_template"
26
+
27
+
28
+ template_2 = SimpleURITemplate.new "http://google.com?q={query}"
29
+
30
+ template_2.expand { 'query' => 'Squibnocket Point tide chart' }
31
+ #=> "http://google.com?q=Squibnocket%20Point%20tide%20chart"
32
+
33
+
34
+ template_3 = SimpleURITemplate.new "http://example.com/page/{page_number}"
35
+
36
+ template_3.expand :page_number => 2
37
+ #=> "http://www.example.com/page/2"
38
+
39
+ == REQUIREMENTS:
40
+
41
+ * Nothin' fancy
42
+
43
+ == INSTALL:
44
+
45
+ * sudo gem install rschenk-simple_uri_template
46
+
47
+ == LICENSE:
48
+
49
+ (The MIT License)
50
+
51
+ Copyright (c) 2009 Ryan Schenk <rschenk@gmail.com>
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "simple_uri_template"
8
+ gem.summary = %Q{A very basic URI Template library}
9
+ gem.email = "rschenk@gmail.com"
10
+ gem.homepage = "http://github.com/rschenk/simple_uri_template"
11
+ gem.authors = ["Ryan Schenk"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+ task :default => :spec
33
+
34
+ require 'rake/rdoctask'
35
+ Rake::RDocTask.new do |rdoc|
36
+ if File.exist?('VERSION.yml')
37
+ config = YAML.load(File.read('VERSION.yml'))
38
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
+ else
40
+ version = ""
41
+ end
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "simple_uri_template #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,13 @@
1
+ require 'uri'
2
+
3
+ class SimpleURITemplate
4
+ attr_accessor :template
5
+
6
+ def initialize(template)
7
+ @template = template
8
+ end
9
+
10
+ def expand(values)
11
+ @template.gsub(/\{(.*?)\}/) { URI.encode( (values[$1] || values[$1.to_sym] || '').to_s ) rescue '' }
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{simple_uri_template}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ryan Schenk"]
9
+ s.date = %q{2009-06-02}
10
+ s.email = %q{rschenk@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/simple_uri_template.rb",
23
+ "simple_uri_template.gemspec",
24
+ "spec/simple_uri_template_spec.rb",
25
+ "spec/spec_helper.rb"
26
+ ]
27
+ s.has_rdoc = true
28
+ s.homepage = %q{http://github.com/rschenk/simple_uri_template}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.1}
32
+ s.summary = %q{A very basic URI Template library}
33
+ s.test_files = [
34
+ "spec/simple_uri_template_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 2
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe SimpleURITemplate do
4
+ describe '#expand' do
5
+ before(:each) do
6
+ @template = SimpleURITemplate.new "http://example.com?q={query}&t={term}"
7
+ end
8
+
9
+ it "should accept a hash with String keys" do
10
+ @template.expand({'query' => 'dude', 'term' => 'bro'}).should == 'http://example.com?q=dude&t=bro'
11
+ end
12
+
13
+ it "should accept a hash with Symbol keys" do
14
+ @template.expand({:query => 'dude', :term => 'bro'}).should == 'http://example.com?q=dude&t=bro'
15
+ end
16
+
17
+
18
+ it 'should ignore pairs in the hash that are not in the template' do
19
+ @template.expand({:query => 'dude', :term => 'bro', :salami => 'egad'}).should == 'http://example.com?q=dude&t=bro'
20
+ end
21
+
22
+ it 'should URI encode the values' do
23
+ @template.expand({:query => 'dude bro', :term => 'bro dude'}).should == 'http://example.com?q=dude%20bro&t=bro%20dude'
24
+ end
25
+
26
+ it 'should gracefully handle values that are not Strings' do
27
+ @template.expand({:query => 1, :term => true}).should == 'http://example.com?q=1&t=true'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'simple_uri_template'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rschenk-simple_uri_template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Schenk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: rschenk@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/simple_uri_template.rb
33
+ - simple_uri_template.gemspec
34
+ - spec/simple_uri_template_spec.rb
35
+ - spec/spec_helper.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/rschenk/simple_uri_template
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A very basic URI Template library
62
+ test_files:
63
+ - spec/simple_uri_template_spec.rb
64
+ - spec/spec_helper.rb