hypermedia_mapper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/hypermedia_mapper.gemspec +26 -0
- data/lib/hypermedia_mapper.rb +10 -0
- data/lib/hypermedia_mapper/link.rb +14 -0
- data/lib/hypermedia_mapper/link_collection.rb +28 -0
- data/lib/hypermedia_mapper/link_parser.rb +11 -0
- data/lib/hypermedia_mapper/version.rb +3 -0
- data/spec/link_collection_spec.rb +38 -0
- data/spec/link_parser_spec.rb +26 -0
- data/spec/link_spec.rb +32 -0
- data/spec/spec_helper.rb +20 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14fdbced901fa6c4a88c618a604b8e9290d729b7
|
4
|
+
data.tar.gz: 371bdd6c6150e3104cf6f59724d13f0dfce97dcb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57660927b6560b5dd0fa6730208ab2ecff180210a977feba69c984ab815fcec31115426ea83ed0eed9807153ceb3873a31b57504791dbcf836f216536a3de4ef
|
7
|
+
data.tar.gz: 8b6cda896345b2ba4996eb973434c97afc64bb38a7c95487c5137ea260a89e94c413a4c97ac9dd25fc565aa8ba42f48fa1b7a9374a4e1690975c1fd99bf56fcf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Redu Educational Technologies
|
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,43 @@
|
|
1
|
+
# HypermediaMapper
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hypermedia_mapper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install hypermedia_mapper
|
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 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
<img src="https://github.com/downloads/redu/redupy/redutech-marca.png" alt="Redu Educational Technologies" width="300">
|
32
|
+
|
33
|
+
This project is maintained and funded by [Redu Educational Techologies](http://tech.redu.com.br).
|
34
|
+
|
35
|
+
# Copyright
|
36
|
+
|
37
|
+
Copyright (c) 2012 Redu Educational Technologies
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
40
|
+
|
41
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hypermedia_mapper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hypermedia_mapper"
|
8
|
+
spec.version = HypermediaMapper::VERSION
|
9
|
+
spec.authors = ["Juliana Lucena", "Guilherme Cavalcanti", "Tiago Ferreira"]
|
10
|
+
spec.email = ["julianalucenaa@gmail.com", "guiocavalcanti@gmail.com", "fltiago@gmail.com"]
|
11
|
+
spec.description = %q{Hypermedia Mapper}
|
12
|
+
spec.summary = %q{Hypermedia Mapper}
|
13
|
+
spec.homepage = "http://github.com/redu/hypermedia_mapper"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.14.rc1'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'virtus', '~> 0.5.4'
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module HypermediaMapper
|
2
|
+
class LinkCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@raw_links = options[:items]
|
7
|
+
@parser_class = options[:parser] || LinkParser
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch(relationship)
|
11
|
+
find { |i| i.rel == relationship.to_s }
|
12
|
+
end
|
13
|
+
|
14
|
+
def each(&block)
|
15
|
+
items.each(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def parser_builder
|
21
|
+
@parser ||= @parser_class.new(@raw_links)
|
22
|
+
end
|
23
|
+
|
24
|
+
def items
|
25
|
+
@items ||= parser_builder.parse
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HypermediaMapper
|
4
|
+
describe LinkCollection do
|
5
|
+
let(:links) do
|
6
|
+
[
|
7
|
+
{ "rel" => "self",
|
8
|
+
"href" => "http://www.redu.com.br/api/subjects/4723" },
|
9
|
+
{ "rel" => "lectures",
|
10
|
+
"href" => "http://www.redu.com.br/api/subjects/4723/lectures" },
|
11
|
+
{ "rel" => "space",
|
12
|
+
"href" => "http://www.redu.com.br/api/courses/2231" },
|
13
|
+
{ "rel" => "course",
|
14
|
+
"href" => "http://www.redu.com.br/api/courses/exemplo-de-aplicativos" },
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:parser) { LinkParser }
|
19
|
+
subject { LinkCollection.new(items: links) }
|
20
|
+
|
21
|
+
it "should fetch the request relationship" do
|
22
|
+
expect(subject.fetch(:space).href).to eq links[2]["href"]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return nil if the link don't exist" do
|
26
|
+
expect(subject.fetch(:environment)).to be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return a link" do
|
30
|
+
expect(subject.fetch(:space)).to be_a Link
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be a enumerable" do
|
34
|
+
expect(subject).to be_a Enumerable
|
35
|
+
expect(subject).to respond_to(:each)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HypermediaMapper
|
4
|
+
describe LinkParser do
|
5
|
+
let(:links) do
|
6
|
+
[
|
7
|
+
{ "rel" => "self", "href" => "http://www.redu.com.br/api/subjects/4723" },
|
8
|
+
{ "rel" => "lectures", "href" => "http://www.redu.com.br/api/subjects/4723/lectures" },
|
9
|
+
{ "rel" => "space", "href" => "http://www.redu.com.br/api/courses/2231" },
|
10
|
+
{ "rel" => "course", "href" => "http://www.redu.com.br/api/courses/exemplo-de-aplicativos" },
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { LinkParser.new(links) }
|
15
|
+
|
16
|
+
it "should parse the links" do
|
17
|
+
expect(subject.parse).to eq links.map { |l| Link.new(l) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should avoid iterating over the links" do
|
21
|
+
subject.parse
|
22
|
+
expect(links).to_not receive(:map)
|
23
|
+
subject.parse
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/link_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HypermediaMapper
|
4
|
+
describe Link do
|
5
|
+
let(:link) do
|
6
|
+
{ "rel" => "space", "href" => "http://www.redu.com.br/api/courses/2231" }
|
7
|
+
end
|
8
|
+
subject { Link.new(link) }
|
9
|
+
|
10
|
+
it "should return the href" do
|
11
|
+
expect(subject.href).to eq link["href"]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the relationship" do
|
15
|
+
expect(subject.relationship).to eq link["rel"]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should alias #rel to #relationship" do
|
19
|
+
expect(subject.rel).to eq subject.relationship
|
20
|
+
end
|
21
|
+
|
22
|
+
context "==" do
|
23
|
+
it "should return true when the objects have the same rel and href" do
|
24
|
+
expect(subject).to eq Link.new(link)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return false otherwise" do
|
28
|
+
expect(subject).to_not eq Link.new({})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'hypermedia_mapper'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hypermedia_mapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juliana Lucena
|
8
|
+
- Guilherme Cavalcanti
|
9
|
+
- Tiago Ferreira
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.3'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.14.rc1
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.14.rc1
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: virtus
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.5.4
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.5.4
|
71
|
+
description: Hypermedia Mapper
|
72
|
+
email:
|
73
|
+
- julianalucenaa@gmail.com
|
74
|
+
- guiocavalcanti@gmail.com
|
75
|
+
- fltiago@gmail.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- .rspec
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- hypermedia_mapper.gemspec
|
87
|
+
- lib/hypermedia_mapper.rb
|
88
|
+
- lib/hypermedia_mapper/link.rb
|
89
|
+
- lib/hypermedia_mapper/link_collection.rb
|
90
|
+
- lib/hypermedia_mapper/link_parser.rb
|
91
|
+
- lib/hypermedia_mapper/version.rb
|
92
|
+
- spec/link_collection_spec.rb
|
93
|
+
- spec/link_parser_spec.rb
|
94
|
+
- spec/link_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: http://github.com/redu/hypermedia_mapper
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Hypermedia Mapper
|
120
|
+
test_files:
|
121
|
+
- spec/link_collection_spec.rb
|
122
|
+
- spec/link_parser_spec.rb
|
123
|
+
- spec/link_spec.rb
|
124
|
+
- spec/spec_helper.rb
|