tag_uri 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rspec
19
+ .rbx/
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - ruby-head
7
+ - jruby-19mode
8
+ - rbx-19mode
9
+
10
+ # whitelist
11
+ branches:
12
+ only:
13
+ - master
14
+ - develop
data/CHANGES.md ADDED
@@ -0,0 +1,14 @@
1
+ # CH CH CH CHANGES #
2
+
3
+ ## v0.0.3 ##
4
+
5
+ * Since the Github repo is called tag-uri (because a hypen is clearer in a URL) I've added tag-uri.rb and taguri.rb to the lib to require the library in case anyone uses the wrong name.
6
+
7
+ ## v0.0.2 ##
8
+
9
+ ### 27th of February 2013 ###
10
+
11
+ * Changed to be a class method, as if it's mixed in to a model then the model will likely want to use that name for the field.
12
+ * Changed the module name, it should all be uppercase so now it is.
13
+
14
+ ----
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tag_uri.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "rake"
8
+ gem "yard"
9
+ gem "maruku"
10
+ gem "wirble"
11
+ end
12
+
13
+ group :test do
14
+ gem "rspec"
15
+ gem "simplecov"
16
+ end
data/LICENCE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Iain Barnett
2
+
3
+ MIT Licence
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,67 @@
1
+ # TagUri
2
+
3
+ An implementation of tag URI's.
4
+ See http://tools.ietf.org/html/rfc4151
5
+
6
+ ### Build status ###
7
+
8
+ Master branch:
9
+ [![Build Status](https://travis-ci.org/yb66/tag_uri.png?branch=master)](https://travis-ci.org/yb66/tag_uri)
10
+
11
+ ## Why? ##
12
+
13
+ Because every Atom entry must have a globally unique ID, in the `id` element.
14
+
15
+ * The ID must be a valid URI, as defined by RFC 2396.
16
+ * The ID must be globally unique, across all Atom feeds, everywhere, for all time. This part is actually easier than it sounds.
17
+ * The ID must never, ever change.
18
+
19
+ Some people use a permalink for this, but we all know that permalinks change, so use a tag URI instead. See http://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id for more.
20
+
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ gem 'tag_uri'
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install tag_uri
35
+
36
+ ## Usage
37
+
38
+ require 'taguri'
39
+
40
+ Given a model:
41
+
42
+ class Post < Sequel::Model # it doesn't have to be Sequel
43
+ end
44
+
45
+ post = Post.create title: "How to make a good ID in Atom"
46
+ post.slug
47
+ # => "howto-atom-linkblog"
48
+ post.created_at
49
+ # => 2004-05-27 00:00:00 0100
50
+
51
+ TagURI.create prefix: "/archives/2004/05/27", host: "diveintomark.org", slug: post.slug, created_at: post.created_at
52
+ # => "tag:diveintomark.org,2013-02-26:/archives/2004/05/27/howto-atom-linkblog"
53
+
54
+ Although you'll probably do something more like this:
55
+
56
+ TagURI.create slug: post.slug, created_at: post.created_at prefix: prefix, host: request.host
57
+
58
+ or something like that.
59
+
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require "bundler/gem_tasks"
2
+
3
+
4
+ task :default => "spec"
5
+
6
+
7
+ desc "(Re-) generate documentation and place it in the docs/ dir."
8
+ task :docs => :"docs:yard"
9
+ namespace :docs do
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new do |t|
12
+ t.files = ['lib/**/*.rb']
13
+ t.options = ['-odocs/', '--no-private']
14
+ end
15
+
16
+ desc "Docs including private methods."
17
+ YARD::Rake::YardocTask.new(:all) do |t|
18
+ t.files = ['lib/**/*.rb']
19
+ t.options = ['-odocs/']
20
+ end
21
+
22
+ desc "How to use the docs."
23
+ task :usage do
24
+ puts "Open the index.html file in the docs directory to read them. Does not include methods marked private unless you ran the 'all' version (you'll only need these if you plan to hack on the library itself)."
25
+ end
26
+ end
27
+
28
+
29
+ require 'rspec/core/rake_task'
30
+
31
+ desc "Run specs"
32
+ RSpec::Core::RakeTask.new do |t|
33
+ t.pattern = "./spec/**/*_spec.rb"
34
+ end
data/lib/tag-uri.rb ADDED
@@ -0,0 +1 @@
1
+ require 'tag_uri'
@@ -0,0 +1,3 @@
1
+ module TagURI
2
+ VERSION = "0.0.5"
3
+ end
data/lib/tag_uri.rb ADDED
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'addressable/uri'
4
+
5
+ # Implementation of tag URI's.
6
+ # @see http://tools.ietf.org/html/rfc4151
7
+ module TagURI
8
+
9
+ class Error < StandardError; end
10
+ class ArgumentError < Error; end
11
+
12
+ DEFAULT_FAILURE_BLOCK = ->(x) {
13
+ fail ArgumentError, "The TagUri#tag_uri method requires a host, a slug, and a created_at time to work. Please check they're provided, as #{x} was nil."
14
+ }
15
+
16
+ # @param [Hash] opts
17
+ # @option opts [String] host The host portion e.g. http://example.com. If the host portion is not given then it is assumed that `self` will provide it.
18
+ # @option opts [String] slug The slugged name e.g. this-is-my-first-post. If a slug is not given then it is assumed that `self` will provide it.
19
+ # @option opts [String] prefix Anything you wish to tack on before the slug in the path e.g. for /posts/this-is-my-first-post pass in "prefix". If a prefix is not given then it will not be added to the string.
20
+ # @option opts [Time] created_at The time the resource was created. If a created_at time is not given then it is assumed that `self` will provide it.
21
+ # @return [String]
22
+ # @example
23
+ # class Posts < Sequel::Model # or whatever ORM you're using.
24
+ # end
25
+ # post = Post.create #…
26
+ # post.slug # => "this-is-my-first-post"
27
+ # TagURI.create host: "http://example.com", prefix: "posts", slug: post.slug, created_at: post.created_at
28
+ def self.create( opts={}, &failure_block )
29
+ opts = opts.dup
30
+ opts[:created_at] ||= Time.now
31
+ opts[:prefix] ||= ""
32
+
33
+ # error checking
34
+ failure_block ||= DEFAULT_FAILURE_BLOCK
35
+ [:created_at,:prefix,:slug,:host].all?{|arg| opts.keys.include? arg }
36
+ opts.each do |k,v|
37
+ if v.nil?
38
+ failure_block.call k.to_s
39
+ end
40
+ end
41
+ opts[:host] = "https://#{opts[:host]}" unless opts[:host] =~ %r{^.+\://.+$} #
42
+ url = File.join opts[:host], opts[:prefix], opts[:slug]
43
+ uri = Addressable::URI.parse url
44
+ uri.scheme = "tag"
45
+ uri.host = "#{uri.host},#{opts[:created_at].strftime "%F"}:"
46
+ uri.to_s.sub(%r{://}, ":")
47
+ end
48
+ end
data/lib/taguri.rb ADDED
@@ -0,0 +1 @@
1
+ require 'tag_uri'
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rspec'
4
+ Spec_dir = File.expand_path( File.dirname __FILE__ )
5
+
6
+ unless Kernel.respond_to?(:require_relative)
7
+ module Kernel
8
+ def require_relative(path)
9
+ require File.join(File.dirname(caller[0]), path.to_str)
10
+ end
11
+ end
12
+ end
13
+
14
+ # code coverage
15
+ require 'simplecov'
16
+ SimpleCov.start do
17
+ add_filter "/vendor/"
18
+ add_filter "/bin/"
19
+ end
20
+
21
+
22
+ Dir[ File.join( Spec_dir, "/support/**/*.rb")].each do |f|
23
+ require f
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ config.treat_symbols_as_metadata_keys_with_true_values = true
28
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'time'
5
+ require 'ostruct'
6
+ require_relative "../lib/tag_uri.rb"
7
+
8
+ describe "Generating a tag uri" do
9
+ let(:url) { "http://diveintomark.org/archives/2004/05/27/howto-atom-linkblog" }
10
+ let(:slug) { "howto-atom-linkblog" }
11
+ let(:created_at) { Time.parse "2004/05/27" }
12
+ let(:host) { "diveintomark.org" }
13
+ let(:prefix) { "/archives/2004/05/27" }
14
+ let(:expected) { "tag:diveintomark.org,2004-05-27:/archives/2004/05/27/howto-atom-linkblog" }
15
+ let(:model) { OpenStruct.new created_at: created_at, slug: slug }
16
+
17
+ context "Given arguments" do
18
+ context "That are valid" do
19
+ subject { TagURI.create prefix: prefix, host: host, created_at: model.created_at, slug: model.slug }
20
+ it { should == expected }
21
+ end
22
+ context "That are not valid" do
23
+ it "raises" do
24
+ expect { TagURI.create prefix: prefix, host: nil, created_at: model.created_at, slug: model.slug }.to raise_error TagURI::ArgumentError
25
+ end
26
+ end
27
+ end
28
+ end
data/tag_uri.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tag_uri/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "tag_uri"
8
+ gem.version = TagURI::VERSION
9
+ gem.authors = ["Iain Barnett"]
10
+ gem.email = ["iainspeed@gmail.com"]
11
+ gem.description = %q{An implementation of tag URI's.
12
+ See http://tools.ietf.org/html/rfc4151}
13
+ gem.summary = %q{Instead of using a permalink as the id for an Atom feed entry, use a tag URI.}
14
+ gem.homepage = "https://github.com/yb66/tag-uri"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.add_dependency("addressable")
21
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tag_uri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Iain Barnett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: addressable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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
+ description: ! "An implementation of tag URI's.\n See http://tools.ietf.org/html/rfc4151"
31
+ email:
32
+ - iainspeed@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .travis.yml
39
+ - CHANGES.md
40
+ - Gemfile
41
+ - LICENCE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - lib/tag-uri.rb
45
+ - lib/tag_uri.rb
46
+ - lib/tag_uri/version.rb
47
+ - lib/taguri.rb
48
+ - spec/spec_helper.rb
49
+ - spec/tag_uri_spec.rb
50
+ - tag_uri.gemspec
51
+ homepage: https://github.com/yb66/tag-uri
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.25
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Instead of using a permalink as the id for an Atom feed entry, use a tag
75
+ URI.
76
+ test_files:
77
+ - spec/spec_helper.rb
78
+ - spec/tag_uri_spec.rb