skeleton 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +106 -0
- data/Rakefile +24 -0
- data/lib/skeleton.rb +10 -0
- data/lib/skeleton/action.rb +46 -0
- data/lib/skeleton/builder.rb +41 -0
- data/lib/skeleton/example.rb +17 -0
- data/lib/skeleton/link.rb +57 -0
- data/lib/skeleton/parameter.rb +32 -0
- data/lib/skeleton/version.rb +3 -0
- data/skeleton.gemspec +26 -0
- data/spec/skeleton/integrated_spec.rb +38 -0
- data/spec/spec_helper.rb +6 -0
- data/test/skeleton/action_test.rb +78 -0
- data/test/skeleton/builder_test.rb +51 -0
- data/test/skeleton/link_test.rb +68 -0
- data/test/test_helper.rb +6 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1b90b70d2ffd87c025cfd71b1de006d2c8b2eb7
|
4
|
+
data.tar.gz: 40574952c4de7e2919e5b3593ea984e9e459b707
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b4b5754b13d7b116feb66afd02576adb07b6510059e50ed2d5c7ae7b245d44313ae5972e22342fe3d9124c13b5b5e163c0ccbb5dfd9d3c0c3215ce2d03710083
|
7
|
+
data.tar.gz: 464593a435ca7e9e6724cdb60e24bc85247c36fd71ded9d3de4ae0d946e893460796b86ec520fd45298ce10a0c87b387d32baecb0918d7ecce4e9e8f9af0fc4e
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
skeleton
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Matthew Johnston
|
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,106 @@
|
|
1
|
+
# Skeleton
|
2
|
+
|
3
|
+
Skeleton is a tool to help people construct `OPTIONS` api responses. This
|
4
|
+
library is simply a data structure with no ties to any single framework.
|
5
|
+
|
6
|
+
## Example
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require 'skeleton'
|
10
|
+
|
11
|
+
skeleton = Skeleton.build do |config|
|
12
|
+
config.define(:get, also: :head) do |action|
|
13
|
+
action.description = 'Display a list of resources'
|
14
|
+
|
15
|
+
action.param('limit') do |p|
|
16
|
+
p.type = 'integer'
|
17
|
+
p.description = 'The number of items desired'
|
18
|
+
p.required = false
|
19
|
+
p.restriction('Minimum value is 0')
|
20
|
+
p.restriction('Maximum value is 9000')
|
21
|
+
end
|
22
|
+
|
23
|
+
action.param('offset') do |p|
|
24
|
+
p.type = 'integer'
|
25
|
+
p.description = 'The offset within the collection'
|
26
|
+
p.required = false
|
27
|
+
p.restriction('Minimum value is 0')
|
28
|
+
end
|
29
|
+
|
30
|
+
action.example do |e|
|
31
|
+
e.param('limit', 10),
|
32
|
+
e.param('offset', 0)
|
33
|
+
end
|
34
|
+
|
35
|
+
action.link(name: 'Self', rel: 'self', href: 'https://api.example.org/resources')
|
36
|
+
end
|
37
|
+
|
38
|
+
config.link(name: 'Documentation', rel: 'docs', href: 'https://docs.example.org/resources')
|
39
|
+
end
|
40
|
+
|
41
|
+
skeleton.to_h
|
42
|
+
```
|
43
|
+
|
44
|
+
Example `Skeleton::Builder#to_h` call
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
{
|
48
|
+
"links"=>[],
|
49
|
+
"GET"=>{
|
50
|
+
"description"=>"Display a list of resources",
|
51
|
+
"parameters"=>{
|
52
|
+
"limit"=>{
|
53
|
+
"type"=>"integer",
|
54
|
+
"description"=>"The number of items desired",
|
55
|
+
"required"=>false,
|
56
|
+
"allowed"=>[],
|
57
|
+
"restrictions"=>[
|
58
|
+
"Minimum value is 0",
|
59
|
+
"Maximum value is 9000"
|
60
|
+
]
|
61
|
+
},
|
62
|
+
"offset"=>{
|
63
|
+
"type"=>"integer",
|
64
|
+
"description"=>"The offset within the collection",
|
65
|
+
"required"=>false,
|
66
|
+
"allowed"=>[],
|
67
|
+
"restrictions"=>[
|
68
|
+
"Minimum value is 0"
|
69
|
+
]
|
70
|
+
}
|
71
|
+
},
|
72
|
+
"links"=>[
|
73
|
+
{
|
74
|
+
"name"=>"Self",
|
75
|
+
"rel"=>"self",
|
76
|
+
"href"=>"https://api.example.org/resources"
|
77
|
+
}
|
78
|
+
],
|
79
|
+
"examples"=>[
|
80
|
+
{
|
81
|
+
"limit"=>10,
|
82
|
+
"offset"=>0
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
## Testing
|
90
|
+
|
91
|
+
We are using MiniTest in order to write tests. Please follow this guideline:
|
92
|
+
|
93
|
+
* If the test is not a unit test, it belongs under `spec`
|
94
|
+
* If the test is a unit test, it belongs under `test`
|
95
|
+
* Test to the best you can
|
96
|
+
|
97
|
+
```sh
|
98
|
+
rake test
|
99
|
+
```
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
* Fork this repo
|
104
|
+
* Do work on a separate branch
|
105
|
+
* Submit a pull request
|
106
|
+
* Drink a beer
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
namespace :test do
|
4
|
+
task :env do
|
5
|
+
$LOAD_PATH.unshift('lib', 'spec', 'test')
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Runs only the units in this project'
|
9
|
+
task :units => [:env] do
|
10
|
+
Dir.glob('./test/**/*_test.rb') { |f| require f }
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Runs only the specs in this project'
|
14
|
+
task :specs => [:env] do
|
15
|
+
Dir.glob('./spec/**/*_spec.rb') { |f| require f }
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Runs all of the tests within this project'
|
19
|
+
task :all => [:units, :specs]
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Runs all of the tests within this project'
|
23
|
+
task :test => 'test:all'
|
24
|
+
task :default => :test
|
data/lib/skeleton.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'skeleton/parameter'
|
2
|
+
require 'skeleton/example'
|
3
|
+
require 'skeleton/link'
|
4
|
+
|
5
|
+
module Skeleton
|
6
|
+
class Action
|
7
|
+
attr_accessor :description, :links, :examples, :parameters
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@parameters = Hash.new
|
11
|
+
@examples = Array.new
|
12
|
+
@links = Hash.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def param(name, &block)
|
16
|
+
parameter = Parameter.new
|
17
|
+
yield(parameter) if block
|
18
|
+
@parameters.store(name.to_s, parameter)
|
19
|
+
end
|
20
|
+
|
21
|
+
def example(&block)
|
22
|
+
example = Example.new
|
23
|
+
yield(example) if block
|
24
|
+
@examples.push(example)
|
25
|
+
end
|
26
|
+
|
27
|
+
def link(args={})
|
28
|
+
raise(ArgumentError, ':rel is required') unless args[:rel]
|
29
|
+
raise(ArgumentError, ':href is required') unless args[:href]
|
30
|
+
|
31
|
+
@links.store(args[:rel], Link.new(args))
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_h
|
35
|
+
hash = {
|
36
|
+
'description' => description,
|
37
|
+
'parameters' => Hash.new,
|
38
|
+
'links' => links.map { |_,link| link.to_h },
|
39
|
+
'examples' => examples.map(&:to_h)
|
40
|
+
}
|
41
|
+
parameters.each { |n, p| hash['parameters'].store(n, p.to_h) }
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
alias_method :to_hash, :to_h
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'skeleton/action'
|
2
|
+
require 'skeleton/link'
|
3
|
+
|
4
|
+
module Skeleton
|
5
|
+
class Builder
|
6
|
+
attr_accessor :actions
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@actions = Hash.new
|
10
|
+
@links = Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def define(verb, options={}, &block)
|
14
|
+
action = Action.new
|
15
|
+
yield(action) if block
|
16
|
+
@actions.store(verb.to_s.downcase, action)
|
17
|
+
Array(options[:also]).each { |v| define(v, &block) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def link(args={})
|
21
|
+
raise(ArgumentError, ':rel is required') unless args[:rel]
|
22
|
+
raise(ArgumentError, ':href is required') unless args[:href]
|
23
|
+
|
24
|
+
@links.store(args[:rel], Link.new(args))
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_h
|
28
|
+
hash = {
|
29
|
+
links: []
|
30
|
+
}
|
31
|
+
@actions.each do |verb, action|
|
32
|
+
hash.store(verb.to_s.upcase, action.to_h)
|
33
|
+
end
|
34
|
+
@links.each do |rel, link|
|
35
|
+
hash['links'] = link.to_h
|
36
|
+
end
|
37
|
+
hash
|
38
|
+
end
|
39
|
+
alias_method :to_hash, :to_h
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Skeleton
|
2
|
+
class Link
|
3
|
+
attr_accessor :rel, :href, :options, :description
|
4
|
+
attr_accessor :templated
|
5
|
+
|
6
|
+
def initialize(args={})
|
7
|
+
raise(ArgumentError, ':rel is required') unless args[:rel]
|
8
|
+
raise(ArgumentError, ':href is required') unless args[:href]
|
9
|
+
|
10
|
+
@options = Hash.new
|
11
|
+
args.each do |k, v|
|
12
|
+
if self.respond_to?("#{k}=")
|
13
|
+
self.send("#{k}=", v)
|
14
|
+
else
|
15
|
+
@options[k.to_s] = v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(m, *args, &block)
|
21
|
+
if @options.key?(m.to_s)
|
22
|
+
@options[m.to_s]
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def templated?
|
29
|
+
!!@templated
|
30
|
+
end
|
31
|
+
|
32
|
+
def <=>(other)
|
33
|
+
@rel <=> other.rel
|
34
|
+
end
|
35
|
+
|
36
|
+
def eql?(other)
|
37
|
+
return false unless other.respond_to?(:rel)
|
38
|
+
@rel.eql?(other.rel)
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_h
|
42
|
+
hash = Hash.new
|
43
|
+
hash['rel'] = @rel
|
44
|
+
hash['href'] = @href
|
45
|
+
@options.each do |k, v|
|
46
|
+
hash[k.to_s] = v
|
47
|
+
end
|
48
|
+
hash
|
49
|
+
end
|
50
|
+
alias_method :to_hash, :to_h
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
opts = options.map { |k,v| '%s="%s";' % [k, v] }.join(' ')
|
54
|
+
'<%s>; rel="%s"; templated="%s" %s' % [href, rel, templated?, opts]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Skeleton
|
2
|
+
class Parameter
|
3
|
+
attr_accessor :type, :description, :required, :allowed, :default, :restrictions
|
4
|
+
|
5
|
+
def initialize(args={})
|
6
|
+
@required = false
|
7
|
+
@allowed = []
|
8
|
+
@restrictions = []
|
9
|
+
|
10
|
+
args.each do |k, v|
|
11
|
+
self.send("#{k}=", v) if self.respond_to?("#{k}=")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def restriction(desc)
|
16
|
+
@restrictions.push(desc)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
hash = {
|
21
|
+
'type' => type,
|
22
|
+
'description' => description,
|
23
|
+
'required' => required
|
24
|
+
}
|
25
|
+
hash['default'] = default if default
|
26
|
+
hash['allowed'] = allowed if allowed
|
27
|
+
hash['restrictions'] = restrictions unless restrictions.empty?
|
28
|
+
hash
|
29
|
+
end
|
30
|
+
alias_method :to_hash, :to_h
|
31
|
+
end
|
32
|
+
end
|
data/skeleton.gemspec
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 'skeleton/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'skeleton'
|
8
|
+
spec.version = Skeleton::VERSION
|
9
|
+
spec.authors = ['Matthew Johnston']
|
10
|
+
spec.email = ['warmwaffles@gmail.com']
|
11
|
+
spec.summary = %q{Construct an api skeleton for options}
|
12
|
+
spec.description = %q{Construct an api skeleton for options}
|
13
|
+
spec.homepage = 'https://github.com/warmwaffles/skeleton'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_dependency('multi_json')
|
22
|
+
|
23
|
+
spec.add_development_dependency('bundler', '~> 1.6')
|
24
|
+
spec.add_development_dependency('rake')
|
25
|
+
spec.add_development_dependency('minitest')
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'skeleton'
|
4
|
+
|
5
|
+
describe 'Full integration test' do
|
6
|
+
it 'when describing collection resource' do
|
7
|
+
skeleton = Skeleton.build do |config|
|
8
|
+
config.define(:get, also: :head) do |action|
|
9
|
+
action.description = 'Display a list of resources'
|
10
|
+
|
11
|
+
action.param('limit') do |p|
|
12
|
+
p.type = 'integer'
|
13
|
+
p.description = 'The number of items desired'
|
14
|
+
p.required = false
|
15
|
+
p.restriction('Minimum value is 0')
|
16
|
+
p.restriction('Maximum value is 9000')
|
17
|
+
end
|
18
|
+
|
19
|
+
action.param('offset') do |p|
|
20
|
+
p.type = 'integer'
|
21
|
+
p.description = 'The offset within the collection'
|
22
|
+
p.required = false
|
23
|
+
p.restriction('Minimum value is 0')
|
24
|
+
end
|
25
|
+
|
26
|
+
action.example do |e|
|
27
|
+
e.param('limit', 10)
|
28
|
+
e.param('offset', 0)
|
29
|
+
end
|
30
|
+
action.link(name: 'Self', rel: 'self', href: 'https://api.example.org/resources')
|
31
|
+
end
|
32
|
+
config.link(name: 'Documentation', rel: 'docs', href: 'https://docs.example.org/resources')
|
33
|
+
end
|
34
|
+
|
35
|
+
refute_nil(skeleton.actions['get'])
|
36
|
+
refute_nil(skeleton.actions['head'])
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'skeleton/action'
|
4
|
+
|
5
|
+
module Skeleton
|
6
|
+
class ActionTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@action = Action.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_param
|
12
|
+
@action.param(:foo) do |param|
|
13
|
+
param.type = 'integer'
|
14
|
+
param.required = true
|
15
|
+
end
|
16
|
+
refute_nil(@action.parameters['foo'], 'expected parameters to contain "foo"')
|
17
|
+
parameter = @action.parameters['foo']
|
18
|
+
assert_equal('integer', parameter.type)
|
19
|
+
assert(parameter.required, 'expected the parameter to be required')
|
20
|
+
|
21
|
+
@action.param('bar[nested]') do |param|
|
22
|
+
param.type = 'string'
|
23
|
+
param.required = false
|
24
|
+
end
|
25
|
+
refute_nil(@action.parameters['bar[nested]'], 'expected parameters to contain "bar[nested]"')
|
26
|
+
parameter = @action.parameters['bar[nested]']
|
27
|
+
assert_equal('string', parameter.type)
|
28
|
+
refute(parameter.required, 'expected the parameter to not be required')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_link
|
32
|
+
assert_raises(ArgumentError) do
|
33
|
+
@action.link({})
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_raises(ArgumentError) do
|
37
|
+
@action.link(name: 'Self', href: 'http://example.org/resource/{id}', templated: true)
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_raises(ArgumentError) do
|
41
|
+
@action.link(name: 'Self', rel: 'self', templated: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
@action.link(name: 'Self', rel: 'self', href: 'http://example.org/resource/{id}', templated: true)
|
45
|
+
refute_nil(@action.links['self'])
|
46
|
+
@action.link(name: 'Root', rel: 'root', href: 'http://example.org/')
|
47
|
+
refute_nil(@action.links['root'])
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_example
|
51
|
+
assert_empty(@action.examples)
|
52
|
+
@action.example do |e|
|
53
|
+
e.param('some[val]', '123')
|
54
|
+
end
|
55
|
+
assert_equal(1, @action.examples.count)
|
56
|
+
@action.example do |e|
|
57
|
+
e.param('some[val]', '123')
|
58
|
+
end
|
59
|
+
assert_equal(2, @action.examples.count)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_to_h
|
63
|
+
@action.description = 'test'
|
64
|
+
@action.param(:foo) do |param|
|
65
|
+
param.type = 'integer'
|
66
|
+
param.required = true
|
67
|
+
param.allowed = [12]
|
68
|
+
end
|
69
|
+
|
70
|
+
hash = @action.to_h
|
71
|
+
|
72
|
+
assert_equal('test', hash['description'])
|
73
|
+
refute_nil(hash['links'])
|
74
|
+
refute_nil(hash['examples'])
|
75
|
+
refute_nil(hash['parameters'])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'skeleton/builder'
|
4
|
+
|
5
|
+
module Skeleton
|
6
|
+
class BuilderTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@builder = Builder.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_define_single
|
12
|
+
@builder.define('get') do |action|
|
13
|
+
action.description = 'something'
|
14
|
+
end
|
15
|
+
refute_nil(@builder.actions['get'])
|
16
|
+
assert_equal('something', @builder.actions['get'].description)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_define_extra
|
20
|
+
@builder.define('get', also: 'post') do |action|
|
21
|
+
action.description = 'something'
|
22
|
+
end
|
23
|
+
refute_nil(@builder.actions['get'])
|
24
|
+
refute_nil(@builder.actions['post'])
|
25
|
+
assert_equal('something', @builder.actions['get'].description)
|
26
|
+
assert_equal('something', @builder.actions['post'].description)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_define_array
|
30
|
+
@builder.define('get', also: ['post']) do |action|
|
31
|
+
action.description = 'something'
|
32
|
+
end
|
33
|
+
refute_nil(@builder.actions['get'])
|
34
|
+
refute_nil(@builder.actions['post'])
|
35
|
+
assert_equal('something', @builder.actions['get'].description)
|
36
|
+
assert_equal('something', @builder.actions['post'].description)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_define_multiple
|
40
|
+
@builder.define('get', also: ['post', 'head']) do |action|
|
41
|
+
action.description = 'something'
|
42
|
+
end
|
43
|
+
refute_nil(@builder.actions['get'])
|
44
|
+
refute_nil(@builder.actions['post'])
|
45
|
+
refute_nil(@builder.actions['head'])
|
46
|
+
assert_equal('something', @builder.actions['get'].description)
|
47
|
+
assert_equal('something', @builder.actions['post'].description)
|
48
|
+
assert_equal('something', @builder.actions['head'].description)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'skeleton/link'
|
4
|
+
|
5
|
+
module Skeleton
|
6
|
+
class LinkTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@link = Link.new(rel: 'self', name: 'Self', href: 'http://example.org')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_initialize
|
12
|
+
assert_raises(ArgumentError) do
|
13
|
+
Link.new
|
14
|
+
end
|
15
|
+
assert_raises(ArgumentError) do
|
16
|
+
Link.new(rel: 'self')
|
17
|
+
end
|
18
|
+
|
19
|
+
Link.new(rel: 'self', href: 'http://example.org')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_method_missing
|
23
|
+
assert_raises(NoMethodError) do
|
24
|
+
@link.foo
|
25
|
+
end
|
26
|
+
|
27
|
+
@link = Link.new(rel: 'self', href: 'http://example.org', foo: 'bar')
|
28
|
+
assert_equal('bar', @link.foo)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_templated?
|
32
|
+
refute(@link.templated?)
|
33
|
+
@link.templated = 'asdf'
|
34
|
+
assert(@link.templated?)
|
35
|
+
@link.templated = false
|
36
|
+
refute(@link.templated?)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_comparable
|
40
|
+
other = Link.new(rel: 'self', name: 'Self', href: 'http://example.org')
|
41
|
+
assert_equal(0, other <=> @link)
|
42
|
+
|
43
|
+
before = Link.new(rel: 'other', href: 'http://example.org')
|
44
|
+
assert_equal(-1, before <=> @link)
|
45
|
+
|
46
|
+
after = Link.new(rel: 'zoo', href: 'http://example.org')
|
47
|
+
assert_equal(1, after <=> @link)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_eql?
|
51
|
+
other = Link.new(rel: 'self', name: 'Self', href: 'http://example.org')
|
52
|
+
assert(@link.eql?(other))
|
53
|
+
|
54
|
+
other = Link.new(rel: 'other', href: 'http://example.org')
|
55
|
+
refute(@link.eql?(other))
|
56
|
+
|
57
|
+
other = Object.new
|
58
|
+
refute(@link.eql?(other))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_to_h
|
62
|
+
hash = @link.to_h
|
63
|
+
assert_equal('self', hash['rel'])
|
64
|
+
assert_equal('Self', hash['name'])
|
65
|
+
assert_equal('http://example.org', hash['href'])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skeleton
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Johnston
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Construct an api skeleton for options
|
70
|
+
email:
|
71
|
+
- warmwaffles@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-gemset"
|
78
|
+
- ".ruby-version"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/skeleton.rb
|
84
|
+
- lib/skeleton/action.rb
|
85
|
+
- lib/skeleton/builder.rb
|
86
|
+
- lib/skeleton/example.rb
|
87
|
+
- lib/skeleton/link.rb
|
88
|
+
- lib/skeleton/parameter.rb
|
89
|
+
- lib/skeleton/version.rb
|
90
|
+
- skeleton.gemspec
|
91
|
+
- spec/skeleton/integrated_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- test/skeleton/action_test.rb
|
94
|
+
- test/skeleton/builder_test.rb
|
95
|
+
- test/skeleton/link_test.rb
|
96
|
+
- test/test_helper.rb
|
97
|
+
homepage: https://github.com/warmwaffles/skeleton
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.2.2
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Construct an api skeleton for options
|
121
|
+
test_files:
|
122
|
+
- spec/skeleton/integrated_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
- test/skeleton/action_test.rb
|
125
|
+
- test/skeleton/builder_test.rb
|
126
|
+
- test/skeleton/link_test.rb
|
127
|
+
- test/test_helper.rb
|