skeleton 0.2.0 → 0.3.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +92 -69
  3. data/Rakefile +2 -7
  4. data/lib/skeleton.rb +14 -4
  5. data/lib/skeleton/attributes.rb +19 -0
  6. data/lib/skeleton/config.rb +38 -0
  7. data/lib/skeleton/contact.rb +17 -0
  8. data/lib/skeleton/documentation.rb +17 -0
  9. data/lib/skeleton/example.rb +20 -6
  10. data/lib/skeleton/header.rb +67 -0
  11. data/lib/skeleton/headers.rb +50 -0
  12. data/lib/skeleton/helpers/controller_helpers.rb +25 -0
  13. data/lib/skeleton/info.rb +40 -0
  14. data/lib/skeleton/item.rb +99 -0
  15. data/lib/skeleton/license.rb +16 -0
  16. data/lib/skeleton/model.rb +31 -0
  17. data/lib/skeleton/operation.rb +157 -0
  18. data/lib/skeleton/parameter.rb +100 -20
  19. data/lib/skeleton/path.rb +111 -0
  20. data/lib/skeleton/response.rb +59 -0
  21. data/lib/skeleton/responses.rb +59 -0
  22. data/lib/skeleton/schema.rb +70 -0
  23. data/lib/skeleton/scopes.rb +24 -0
  24. data/lib/skeleton/security_definitions.rb +46 -0
  25. data/lib/skeleton/security_requirement.rb +29 -0
  26. data/lib/skeleton/security_scheme.rb +47 -0
  27. data/lib/skeleton/serializers/swagger.rb +212 -0
  28. data/lib/skeleton/structure.rb +191 -0
  29. data/lib/skeleton/tag.rb +24 -0
  30. data/lib/skeleton/version.rb +1 -1
  31. data/spec/integrations/use_case_spec.rb +130 -0
  32. data/spec/skeleton/operation_spec.rb +113 -0
  33. data/spec/skeleton/serializers/contact_spec.rb +30 -0
  34. data/spec/skeleton/serializers/documentation_spec.rb +23 -0
  35. data/spec/skeleton/serializers/header_spec.rb +57 -0
  36. data/spec/spec_helper.rb +8 -0
  37. metadata +36 -15
  38. data/lib/skeleton/action.rb +0 -46
  39. data/lib/skeleton/builder.rb +0 -47
  40. data/lib/skeleton/link.rb +0 -57
  41. data/spec/skeleton/integrated_spec.rb +0 -38
  42. data/test/skeleton/action_test.rb +0 -78
  43. data/test/skeleton/builder_test.rb +0 -51
  44. data/test/skeleton/link_test.rb +0 -68
  45. data/test/test_helper.rb +0 -6
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ require 'skeleton/operation'
4
+
5
+ describe Skeleton::Operation do
6
+ describe '#summary=' do
7
+ it 'sets the summary' do
8
+ operation = Skeleton::Operation.new
9
+ operation.summary = 'foo bar'
10
+ assert_equal('foo bar', operation.summary)
11
+ end
12
+ end
13
+
14
+ describe '#summary?' do
15
+ context 'when not set' do
16
+ it 'returns false' do
17
+ operation = Skeleton::Operation.new
18
+ refute(operation.summary?)
19
+ end
20
+ end
21
+
22
+ context 'when set' do
23
+ it 'returns true' do
24
+ operation = Skeleton::Operation.new(summary: 'foo bar')
25
+ assert(operation.summary?)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#consumes' do
31
+ context 'when not set' do
32
+ it 'returns an empty array' do
33
+ operation = Skeleton::Operation.new
34
+ assert_empty(operation.consumes)
35
+ end
36
+ end
37
+
38
+ context 'when set' do
39
+ it 'returns strings' do
40
+ operation = Skeleton::Operation.new({consumes: ['application/json', 'application/xml']})
41
+ assert_includes(operation.consumes, 'application/json')
42
+ assert_includes(operation.consumes, 'application/xml')
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#consumes?' do
48
+ context 'when not set' do
49
+ it 'returns an empty array' do
50
+ operation = Skeleton::Operation.new
51
+ refute(operation.consumes?)
52
+ end
53
+ end
54
+
55
+ context 'when set' do
56
+ it 'returns strings' do
57
+ operation = Skeleton::Operation.new({consumes: ['application/json', 'application/xml']})
58
+ assert(operation.consumes?)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#produces' do
64
+ context 'when not set' do
65
+ it 'returns an empty array' do
66
+ operation = Skeleton::Operation.new
67
+ assert_empty(operation.produces)
68
+ end
69
+ end
70
+
71
+ context 'when set' do
72
+ it 'returns strings' do
73
+ operation = Skeleton::Operation.new({produces: ['application/json', 'application/xml']})
74
+ assert_includes(operation.produces, 'application/json')
75
+ assert_includes(operation.produces, 'application/xml')
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#produces?' do
81
+ context 'when not set' do
82
+ it 'returns an empty array' do
83
+ operation = Skeleton::Operation.new
84
+ refute(operation.produces?)
85
+ end
86
+ end
87
+
88
+ context 'when set' do
89
+ it 'returns strings' do
90
+ operation = Skeleton::Operation.new({produces: ['application/json', 'application/xml']})
91
+ assert(operation.produces?)
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '#to_h' do
97
+ context 'when nothing is set' do
98
+ it 'returns an empty hash' do
99
+ operation = Skeleton::Operation.new
100
+ assert_empty(operation.to_h)
101
+ end
102
+ end
103
+
104
+ context 'when consumes is set' do
105
+ it 'returns a hash with the consumes field' do
106
+ operation = Skeleton::Operation.new({consumes: ['application/json', 'application/xml']})
107
+ hash = operation.to_h
108
+ refute_empty(hash, 'expected the hash to contain data')
109
+ assert(hash.key?(:consumes), 'expected the hash to contain :consumes')
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ require 'skeleton/contact'
4
+
5
+ describe Skeleton::Contact do
6
+ before do
7
+ @contact = Skeleton::Contact.new
8
+ end
9
+
10
+ describe '#name=' do
11
+ it 'sets the name' do
12
+ @contact.name = 'foo'
13
+ assert_equal('foo', @contact.name)
14
+ end
15
+ end
16
+
17
+ describe '#email=' do
18
+ it 'sets the email' do
19
+ @contact.email = 'foo'
20
+ assert_equal('foo', @contact.email)
21
+ end
22
+ end
23
+
24
+ describe '#url=' do
25
+ it 'sets the url' do
26
+ @contact.url = 'foo'
27
+ assert_equal('foo', @contact.url)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ require 'skeleton/documentation'
4
+
5
+ describe Skeleton::Documentation do
6
+ before do
7
+ @documentation = Skeleton::Documentation.new
8
+ end
9
+
10
+ describe '#description=' do
11
+ it 'sets the description' do
12
+ @documentation.description = 'foo'
13
+ assert_equal('foo', @documentation.description)
14
+ end
15
+ end
16
+
17
+ describe '#url=' do
18
+ it 'sets the url' do
19
+ @documentation.url = 'foo'
20
+ assert_equal('foo', @documentation.url)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ require 'skeleton/header'
4
+
5
+ describe Skeleton::Header do
6
+ before do
7
+ @header = Skeleton::Header.new
8
+ end
9
+
10
+ describe '#exclusive_maximum?' do
11
+ describe 'when set' do
12
+ it 'is true' do
13
+ @header.exclusive_maximum = 10
14
+ assert(@header.exclusive_maximum?)
15
+ end
16
+ end
17
+
18
+ describe 'when not set' do
19
+ it 'is false' do
20
+ @header.exclusive_maximum = nil
21
+ refute(@header.exclusive_maximum?)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#exclusive_minimum?' do
27
+ describe 'when set' do
28
+ it 'is true' do
29
+ @header.exclusive_minimum = 10
30
+ assert(@header.exclusive_minimum?)
31
+ end
32
+ end
33
+
34
+ describe 'when not set' do
35
+ it 'is false' do
36
+ @header.exclusive_minimum = nil
37
+ refute(@header.exclusive_minimum?)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#unique_items?' do
43
+ describe 'when set' do
44
+ it 'is true' do
45
+ @header.unique_items = 10
46
+ assert(@header.unique_items?)
47
+ end
48
+ end
49
+
50
+ describe 'when not set' do
51
+ it 'is false' do
52
+ @header.unique_items = nil
53
+ refute(@header.unique_items?)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -4,3 +4,11 @@ require 'bundler'
4
4
  require 'minitest/autorun'
5
5
  require 'minitest/spec'
6
6
  require 'minitest/pride'
7
+
8
+ module Minitest
9
+ class Spec
10
+ class << self
11
+ alias_method :context, :describe
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skeleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Johnston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-30 00:00:00.000000000 Z
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -81,19 +81,39 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/skeleton.rb
84
- - lib/skeleton/action.rb
85
- - lib/skeleton/builder.rb
84
+ - lib/skeleton/attributes.rb
85
+ - lib/skeleton/config.rb
86
+ - lib/skeleton/contact.rb
87
+ - lib/skeleton/documentation.rb
86
88
  - lib/skeleton/example.rb
87
- - lib/skeleton/link.rb
89
+ - lib/skeleton/header.rb
90
+ - lib/skeleton/headers.rb
91
+ - lib/skeleton/helpers/controller_helpers.rb
92
+ - lib/skeleton/info.rb
93
+ - lib/skeleton/item.rb
94
+ - lib/skeleton/license.rb
95
+ - lib/skeleton/model.rb
96
+ - lib/skeleton/operation.rb
88
97
  - lib/skeleton/parameter.rb
98
+ - lib/skeleton/path.rb
99
+ - lib/skeleton/response.rb
100
+ - lib/skeleton/responses.rb
101
+ - lib/skeleton/schema.rb
102
+ - lib/skeleton/scopes.rb
103
+ - lib/skeleton/security_definitions.rb
104
+ - lib/skeleton/security_requirement.rb
105
+ - lib/skeleton/security_scheme.rb
106
+ - lib/skeleton/serializers/swagger.rb
107
+ - lib/skeleton/structure.rb
108
+ - lib/skeleton/tag.rb
89
109
  - lib/skeleton/version.rb
90
110
  - skeleton.gemspec
91
- - spec/skeleton/integrated_spec.rb
111
+ - spec/integrations/use_case_spec.rb
112
+ - spec/skeleton/operation_spec.rb
113
+ - spec/skeleton/serializers/contact_spec.rb
114
+ - spec/skeleton/serializers/documentation_spec.rb
115
+ - spec/skeleton/serializers/header_spec.rb
92
116
  - 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
117
  homepage: https://github.com/warmwaffles/skeleton
98
118
  licenses:
99
119
  - MIT
@@ -119,9 +139,10 @@ signing_key:
119
139
  specification_version: 4
120
140
  summary: Construct an api skeleton for options
121
141
  test_files:
122
- - spec/skeleton/integrated_spec.rb
142
+ - spec/integrations/use_case_spec.rb
143
+ - spec/skeleton/operation_spec.rb
144
+ - spec/skeleton/serializers/contact_spec.rb
145
+ - spec/skeleton/serializers/documentation_spec.rb
146
+ - spec/skeleton/serializers/header_spec.rb
123
147
  - 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
148
+ has_rdoc:
@@ -1,46 +0,0 @@
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
@@ -1,47 +0,0 @@
1
- require 'multi_json'
2
-
3
- require 'skeleton/action'
4
- require 'skeleton/link'
5
-
6
- module Skeleton
7
- class Builder
8
- attr_accessor :actions
9
-
10
- def initialize
11
- @actions = Hash.new
12
- @links = Hash.new
13
- end
14
-
15
- def define(verb, options={}, &block)
16
- action = Action.new
17
- yield(action) if block
18
- @actions.store(verb.to_s.downcase, action)
19
- Array(options[:also]).each { |v| define(v, &block) }
20
- end
21
-
22
- def link(args={})
23
- raise(ArgumentError, ':rel is required') unless args[:rel]
24
- raise(ArgumentError, ':href is required') unless args[:href]
25
-
26
- @links.store(args[:rel], Link.new(args))
27
- end
28
-
29
- def to_h
30
- hash = {
31
- links: []
32
- }
33
- @actions.each do |verb, action|
34
- hash.store(verb.to_s.upcase, action.to_h)
35
- end
36
- @links.each do |rel, link|
37
- hash['links'] = link.to_h
38
- end
39
- hash
40
- end
41
- alias_method :to_hash, :to_h
42
-
43
- def to_json(*)
44
- MultiJson.dump(to_h)
45
- end
46
- end
47
- end
@@ -1,57 +0,0 @@
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