opushon 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 651d12bd2b0f56b85c3cc5a5a5de3b1d2caf285b
4
+ data.tar.gz: 9eac2b5b7e0dce96c0db5ac5aaa26d860263dd53
5
+ SHA512:
6
+ metadata.gz: aa3758fb3d93c9ddc489541a392d54c54400e226562e97bd03ef5a832cb28646e5a4dbc917ba081e7a777b1a208a6842534df5d0d503d363c0679f477c298a3b
7
+ data.tar.gz: 43e02e8f85644870cdc5ae64615c529227c39e913ebe48c9700c2a39b1b3990699db32cd699ac794697960a6b46c144612fdf63a47fbcba5f93950fb329f1ff9
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.0-preview2
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ script: 'bundle exec rake test:coverage'
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.3
6
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Cyril Wack
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,37 @@
1
+ # Opushon
2
+
3
+ An [Opushon's body](https://github.com/cyril/opushon) parser and emitter.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'opushon'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install opushon
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # Parse some Opushon
25
+ Opushon.load('{"DELETE":{"title": "Delete issues","description":"Remove every issues."}}') # => an Opushon instance
26
+
27
+ # Emit some Opushon
28
+ Opushon.dump(an Opushon instance) # => '{"DELETE":{"title": "Delete issues","description":"Remove every issues."}}'
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. [Fork it](https://github.com/cyril/opushon.rb/fork)
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = File.join 'spec', '**', '*_spec.rb'
6
+ t.verbose = true
7
+ t.warning = true
8
+ end
9
+
10
+ namespace :test do
11
+ task :coverage do
12
+ ENV['COVERAGE'] = 'true'
13
+ Rake::Task['test'].invoke
14
+ end
15
+ end
16
+
17
+ task(:doc_stats) { ruby '-S yard stats' }
18
+ task default: [:test, :doc_stats]
data/VERSION.semver ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,29 @@
1
+ require_relative 'type'
2
+
3
+ # Namespace for the Opushon library.
4
+ module Opushon
5
+ # Parse a Opushon string in opushon.
6
+ class Attribute
7
+ def initialize(properties)
8
+ type = properties.delete('type') { 'string' }
9
+ @type = Type.const_get(type.capitalize).new(properties)
10
+
11
+ @nullifiable = properties.delete('nullifiable') { true }
12
+ @multiple = properties.delete('multiple') { false }
13
+ @description = properties.delete('description') { '' }
14
+ @options = properties.delete('options') { nil }
15
+
16
+ @other_settings = properties
17
+ end
18
+
19
+ # Dump attribute's properties to a hash.
20
+ def to_h
21
+ {
22
+ 'nullifiable' => @nullifiable,
23
+ 'multiple' => @multiple,
24
+ 'description' => @description,
25
+ 'options' => @options
26
+ }.merge(@other_settings).merge(@type.to_h)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ # Namespace for the Opushon library.
2
+ module Opushon
3
+ # Raised if anything goes wrong.
4
+ class BaseError < RuntimeError
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'base_error'
2
+
3
+ # Namespace for the Opushon library.
4
+ module Opushon
5
+ # Raised if anything goes wrong while parsing a string.
6
+ class SyntaxError < BaseError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'syntax_error'
2
+
3
+ # Namespace for the Opushon library.
4
+ module Opushon
5
+ # Raised if anything goes wrong while parsing a verb.
6
+ class VerbError < SyntaxError
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ Dir[File.join File.dirname(__FILE__), 'error', '**' '*.rb'].each do |filename|
2
+ require_relative filename
3
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'option'
2
+ require_relative 'option_object'
3
+ require_relative 'verb'
4
+ require 'json'
5
+
6
+ # Namespace for the Opushon library.
7
+ module Opushon
8
+ # Parse a Opushon string in opushon.
9
+ class Instance
10
+ def initialize(opushon)
11
+ o = JSON.load opushon
12
+
13
+ unless o.is_a?(Hash)
14
+ fail SyntaxError
15
+ end
16
+
17
+ unless o.keys.map(&:to_sym).to_set.subset? VERBS
18
+ fail VerbError
19
+ end
20
+
21
+ @options = {}
22
+ o.each do |verb, option_object|
23
+ @options.update verb => OptionObject.new(verb, option_object)
24
+ end
25
+ end
26
+
27
+ # Dump instance's opushon to a hash.
28
+ #
29
+ # @api public
30
+ def to_h
31
+ Hash[@options.each { |k,v| @options[k] = v.to_h }]
32
+ end
33
+
34
+ # Runs all the validations within the current context.
35
+ #
36
+ # @return [Boolean] Returns true if no errors are found, false otherwise.
37
+ #
38
+ # @api public
39
+ def valid?(verb, example)
40
+ @options.fetch(verb.to_s).valid? example
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ # Namespace for the Opushon library.
2
+ module Opushon
3
+ # Parse a Opushon string in opushon.
4
+ class Option
5
+ def initialize(option_object)
6
+ @option_object = option_object
7
+ end
8
+
9
+ # Dump instance's opushon to a hash.
10
+ def to_h
11
+ @option_object.to_h
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'attribute'
2
+ require_relative 'verb'
3
+
4
+ # Namespace for the Opushon library.
5
+ module Opushon
6
+ # Parse a Opushon string in opushon.
7
+ class OptionObject
8
+ def initialize(verb, members)
9
+ @verb = verb
10
+ @title = members.delete('title') { '' }
11
+ @description = members.delete('description') { '' }
12
+
13
+ @query_string = {}
14
+ query_string = members.delete('query_string') { Hash.new }
15
+ query_string.each do |key, properties|
16
+ @query_string.update key => Attribute.new(properties)
17
+ end
18
+
19
+ @parameters = {}
20
+ parameters = members.delete('parameters') { Hash.new }
21
+ parameters.each do |key, properties|
22
+ @parameters.update key => Attribute.new(properties)
23
+ end
24
+
25
+ @example = members.delete('example') { nil }
26
+
27
+ unless @example.nil?
28
+ fail InvalidExample unless valid?(@example)
29
+ end
30
+
31
+ @other_settings = members
32
+ end
33
+
34
+ # Dump option object's members to a hash.
35
+ def to_h
36
+ {
37
+ 'title' => @title,
38
+ 'description' => @description,
39
+ 'query_string' => @query_string.each { |k,v| @query_string[k] = v.to_h },
40
+ 'parameters' => @parameters.each { |k,v| @parameters[k] = v.to_h },
41
+ 'example' => @example
42
+ }.merge(@other_settings)
43
+ end
44
+
45
+ # Runs all the validations within the current context.
46
+ #
47
+ # @return [Boolean] Returns true if no errors are found, false otherwise.
48
+ def valid?(example)
49
+ unless VERBS.include?(@verb.to_sym)
50
+ fail VerbError
51
+ end
52
+
53
+ true
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ # Namespace for the Opushon library.
2
+ module Opushon
3
+ module Type
4
+ # Abstract class.
5
+ class Base
6
+ def default
7
+ nil
8
+ end
9
+
10
+ def to_h
11
+ {
12
+ 'default' => default,
13
+ 'type' => self.class.name.split('::').last.downcase
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'base'
2
+
3
+ # Namespace for the Opushon library.
4
+ module Opushon
5
+ module Type
6
+ # The type boolean.
7
+ class Boolean < Base
8
+ def default
9
+ false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'base'
2
+
3
+ # Namespace for the Opushon library.
4
+ module Opushon
5
+ module Type
6
+ # The type number.
7
+ class Number < Base
8
+ def initialize(constraints)
9
+ @min = constraints.delete('min') { nil }
10
+ @max = constraints.delete('max') { nil }
11
+ @step = constraints.delete('step') { nil }
12
+ end
13
+
14
+ def default
15
+ 0
16
+ end
17
+
18
+ def to_h
19
+ super.merge({
20
+ 'min' => @min,
21
+ 'max' => @max,
22
+ 'step' => @step
23
+ })
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'base'
2
+
3
+ # Namespace for the Opushon library.
4
+ module Opushon
5
+ module Type
6
+ # The type string.
7
+ class String < Base
8
+ def initialize(constraints)
9
+ @minlen = constraints.delete('minlen') { nil }
10
+ @maxlen = constraints.delete('maxlen') { nil }
11
+ @pattern = constraints.delete('pattern') { nil }
12
+ end
13
+
14
+ def default
15
+ ''
16
+ end
17
+
18
+ def to_h
19
+ super.merge({
20
+ 'minlen' => @minlen,
21
+ 'maxlen' => @maxlen,
22
+ 'pattern' => @pattern
23
+ })
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ # Namespace for the Opushon library.
2
+ module Opushon
3
+ # Contains available types.
4
+ module Type
5
+ end
6
+ end
7
+
8
+ Dir[File.join File.dirname(__FILE__), 'type', '*.rb'].each do |filename|
9
+ require_relative filename
10
+ end
@@ -0,0 +1,7 @@
1
+ module Opushon
2
+ module Verb
3
+ # Global verb object structure.
4
+ class Base
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'base'
2
+
3
+ module Opushon
4
+ module Verb
5
+ # HTTP DELETE verb object
6
+ class Delete
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'base'
2
+
3
+ module Opushon
4
+ module Verb
5
+ # HTTP GET verb object
6
+ class Get
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'base'
2
+
3
+ module Opushon
4
+ module Verb
5
+ # HTTP HEAD verb object
6
+ class Head
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'base'
2
+
3
+ module Opushon
4
+ module Verb
5
+ # HTTP PATCH verb object
6
+ class Patch
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'base'
2
+
3
+ module Opushon
4
+ module Verb
5
+ # HTTP POST verb object
6
+ class Post
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'base'
2
+
3
+ module Opushon
4
+ module Verb
5
+ # HTTP PUT verb object
6
+ class Put
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'set'
2
+
3
+ Dir[File.join File.dirname(__FILE__), 'verb', '*.rb'].each do |filename|
4
+ require_relative filename
5
+ end
6
+
7
+ # Namespace for the Opushon library.
8
+ module Opushon
9
+ # Allowed verbs
10
+ VERBS = Verb.constants.delete_if { |sym| sym.equal?(:Base) }.map(&:upcase).to_set
11
+ end
@@ -0,0 +1,7 @@
1
+ # Namespace for the Opushon library.
2
+ module Opushon
3
+ # Gem version
4
+ VERSION = File.open(
5
+ Pathname.new(__FILE__).join '..', '..', '..', 'VERSION.semver'
6
+ ).read.chomp.to_sym
7
+ end
data/lib/opushon.rb ADDED
@@ -0,0 +1,22 @@
1
+ require_relative File.join(*%w(opushon error))
2
+ require_relative File.join(*%w(opushon instance))
3
+ require_relative File.join(*%w(opushon version))
4
+
5
+ # Namespace for the Opushon library.
6
+ #
7
+ # @api private
8
+ module Opushon
9
+ class << self
10
+ # Load opushon in to a Ruby data structure.
11
+ # @api public
12
+ def load(opushon)
13
+ Instance.new(opushon)
14
+ end
15
+
16
+ # Dump Ruby object o to a Opushon string.
17
+ # @api public
18
+ def dump(o)
19
+ JSON.dump o
20
+ end
21
+ end
22
+ end
data/opushon.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'opushon'
3
+ spec.version = File.read('VERSION.semver')
4
+ spec.authors = ['Cyril Wack']
5
+ spec.email = ['contact@cyril.email']
6
+ spec.summary = 'A HTTP Opushon parser and emitter'
7
+ spec.description = 'An Opushon\'s body parser and emitter.'
8
+ spec.homepage = 'https://github.com/cyril/opushon.rb'
9
+ spec.license = 'MIT'
10
+
11
+ spec.files = `git ls-files -z`.split("\x0")
12
+ spec.test_files = spec.files.grep(/^spec\//)
13
+ spec.require_paths = ['lib']
14
+ spec.required_ruby_version = '>= 2.0.0'
15
+
16
+ spec.add_development_dependency 'bundler', '~> 1.7'
17
+ spec.add_development_dependency 'minitest', '~> 5'
18
+ spec.add_development_dependency 'rake', '~> 10.0'
19
+ spec.add_development_dependency 'yard', '~> 0.8'
20
+ spec.add_development_dependency 'coveralls', '~> 0.7'
21
+ end
@@ -0,0 +1 @@
1
+ require_relative File.join(*%w(.. spec_helper))
@@ -0,0 +1,9 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Opushon::VERSION do
4
+ it 'MUST return the version' do
5
+ Opushon::VERSION.must_equal File.open(
6
+ Pathname.new(__FILE__).join(*%w(.. .. .. VERSION.semver))
7
+ ).read.chomp.to_sym
8
+ end
9
+ end
@@ -0,0 +1,353 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Opushon do
4
+ describe '.load' do
5
+ let :options_account do
6
+ Opushon.load('{
7
+ "DELETE": {
8
+ "title": "Delete account",
9
+ "description": "Remove my account please!!",
10
+ "foo": "bar"
11
+ }
12
+ }')
13
+ end
14
+
15
+ let :options_issues do
16
+ Opushon.load('{
17
+ "GET": {
18
+ "title": "List issues",
19
+ "description": "List all issues across all the authenticated user\'s visible repositories.",
20
+ "query_string": {
21
+ "page": {
22
+ "type": "number",
23
+ "description": "Identify the page to return.",
24
+ "min": 1,
25
+ "max": null,
26
+ "step": 1
27
+ },
28
+ "per_page": {
29
+ "type": "number",
30
+ "description": "Indicate the number of issues per page.",
31
+ "min": 1,
32
+ "max": 100,
33
+ "step": 1
34
+ },
35
+ "state": {
36
+ "description": "Indicates the state of the issues to return.",
37
+ "options": {
38
+ "open": "Open",
39
+ "closed": "Closed",
40
+ "all": "All"
41
+ },
42
+ "default": "open",
43
+ "multiple": true,
44
+ "nullifiable": true
45
+ }
46
+ },
47
+ "parameters": {
48
+ "created_at": {
49
+ "type": "string",
50
+ "description": "The datetime that the resource was created at.",
51
+ "nullifiable": false
52
+ },
53
+ "title": {
54
+ "type": "string",
55
+ "description": "The title of the resource.",
56
+ "maxlen": 255,
57
+ "nullifiable": false
58
+ },
59
+ "body": {
60
+ "type": "string",
61
+ "description": "The body of the resource.",
62
+ "maxlen": 10000,
63
+ "nullifiable": true
64
+ },
65
+ "state": {
66
+ "type": "string",
67
+ "description": "Indicates the state of the issue.",
68
+ "maxlen": 255,
69
+ "options": {
70
+ "open": "Open",
71
+ "closed": "Closed",
72
+ "all": "All"
73
+ },
74
+ "multiple": false,
75
+ "nullifiable": false
76
+ }
77
+ },
78
+ "example": [
79
+ {
80
+ "created_at": "2014-01-01T01:01:01Z",
81
+ "title": "Found a bug",
82
+ "body": "I\'m having a problem with this.",
83
+ "state": "open"
84
+ }
85
+ ]
86
+ },
87
+ "POST": {
88
+ "title": "Create an issue",
89
+ "description": "Any user with pull access to a repository can create an issue.",
90
+ "query_string": {},
91
+ "parameters": {
92
+ "title": {
93
+ "type": "string",
94
+ "description": "Issue title.",
95
+ "maxlen": 255,
96
+ "nullifiable": false
97
+ },
98
+ "body": {
99
+ "type": "string",
100
+ "description": "Issue body.",
101
+ "nullifiable": true
102
+ },
103
+ "labels": {
104
+ "type": "string",
105
+ "description": "Labels to associate with this issue.",
106
+ "multiple": true,
107
+ "nullifiable": true,
108
+ "options": {
109
+ "label_1": "Java",
110
+ "label_2": "Ruby",
111
+ "label_3": "Elixir"
112
+ }
113
+ }
114
+ },
115
+ "example": {
116
+ "title": "Found a bug",
117
+ "body": "I\'m having a problem with this.",
118
+ "labels": [
119
+ "label_1",
120
+ "label_2"
121
+ ]
122
+ }
123
+ },
124
+ "DELETE": {
125
+ "title": "Delete issues",
126
+ "description": "Remove every issues."
127
+ }
128
+ }')
129
+ end
130
+
131
+ it 'MUST raise a JSON parser error' do
132
+ lambda do
133
+ Opushon.load('{"DELETE":{"title":"Delete issues"')
134
+ end.must_raise(JSON::ParserError)
135
+ end
136
+
137
+ it 'MUST raise a Opushon syntax error' do
138
+ lambda do
139
+ Opushon.load('["BOOM"]')
140
+ end.must_raise(Opushon::SyntaxError)
141
+ end
142
+
143
+ it 'MUST raise a Opushon verb error' do
144
+ lambda do
145
+ Opushon.load('{"BOOM":{}}')
146
+ end.must_raise(Opushon::VerbError)
147
+ end
148
+
149
+ describe '#to_h' do
150
+ it 'MUST load opushon in to a Ruby data structure' do
151
+ options_account.to_h.must_equal({
152
+ 'DELETE' => {
153
+ 'title' => 'Delete account',
154
+ 'description' => 'Remove my account please!!',
155
+ 'query_string' => {},
156
+ 'parameters' => {},
157
+ 'example' => nil,
158
+ 'foo' => 'bar'
159
+ }
160
+ })
161
+ end
162
+
163
+ it 'MUST load opushon having query_string and parameters' do
164
+ options_issues.to_h.must_equal({
165
+ "GET"=>{
166
+ "title"=>"List issues",
167
+ "description"=>"List all issues across all the authenticated user's visible repositories.",
168
+ "query_string"=>{
169
+ "page"=>{
170
+ "nullifiable"=>true,
171
+ "multiple"=>false,
172
+ "description"=>"Identify the page to return.",
173
+ "options"=>nil,
174
+ "default"=>0,
175
+ "type"=>"number",
176
+ "min"=>1,
177
+ "max"=>nil,
178
+ "step"=>1
179
+ },
180
+ "per_page"=>{
181
+ "nullifiable"=>true,
182
+ "multiple"=>false,
183
+ "description"=>"Indicate the number of issues per page.",
184
+ "options"=>nil,
185
+ "default"=>0,
186
+ "type"=>"number",
187
+ "min"=>1,
188
+ "max"=>100,
189
+ "step"=>1
190
+ },
191
+ "state"=>{
192
+ "nullifiable"=>true,
193
+ "multiple"=>true,
194
+ "description"=>"Indicates the state of the issues to return.",
195
+ "options"=>{
196
+ "open"=>"Open",
197
+ "closed"=>"Closed",
198
+ "all"=>"All"
199
+ },
200
+ "default"=>"",
201
+ "type"=>"string",
202
+ "minlen"=>nil,
203
+ "maxlen"=>nil,
204
+ "pattern"=>nil
205
+ }
206
+ },
207
+ "parameters"=>{
208
+ "created_at"=>{
209
+ "nullifiable"=>false,
210
+ "multiple"=>false,
211
+ "description"=>"The datetime that the resource was created at.",
212
+ "options"=>nil,
213
+ "default"=>"",
214
+ "type"=>"string",
215
+ "minlen"=>nil,
216
+ "maxlen"=>nil,
217
+ "pattern"=>nil
218
+ },
219
+ "title"=>{
220
+ "nullifiable"=>false,
221
+ "multiple"=>false,
222
+ "description"=>"The title of the resource.",
223
+ "options"=>nil,
224
+ "default"=>"",
225
+ "type"=>"string",
226
+ "minlen"=>nil,
227
+ "maxlen"=>255,
228
+ "pattern"=>nil
229
+ },
230
+ "body"=>{
231
+ "nullifiable"=>true,
232
+ "multiple"=>false,
233
+ "description"=>"The body of the resource.",
234
+ "options"=>nil,
235
+ "default"=>"",
236
+ "type"=>"string",
237
+ "minlen"=>nil,
238
+ "maxlen"=>10000,
239
+ "pattern"=>nil
240
+ },
241
+ "state"=>{
242
+ "nullifiable"=>false,
243
+ "multiple"=>false,
244
+ "description"=>"Indicates the state of the issue.",
245
+ "options"=>{
246
+ "open"=>"Open",
247
+ "closed"=>"Closed",
248
+ "all"=>"All"
249
+ },
250
+ "default"=>"",
251
+ "type"=>"string",
252
+ "minlen"=>nil,
253
+ "maxlen"=>255,
254
+ "pattern"=>nil
255
+ }
256
+ },
257
+ "example"=>[
258
+ {
259
+ "created_at"=>"2014-01-01T01:01:01Z",
260
+ "title"=>"Found a bug",
261
+ "body"=>"I'm having a problem with this.",
262
+ "state"=>"open"
263
+ }
264
+ ]
265
+ },
266
+ "POST"=>{
267
+ "title"=>"Create an issue",
268
+ "description"=>"Any user with pull access to a repository can create an issue.",
269
+ "query_string"=>{},
270
+ "parameters"=>{
271
+ "title"=>{
272
+ "nullifiable"=>false,
273
+ "multiple"=>false,
274
+ "description"=>"Issue title.",
275
+ "options"=>nil,
276
+ "default"=>"",
277
+ "type"=>"string",
278
+ "minlen"=>nil,
279
+ "maxlen"=>255,
280
+ "pattern"=>nil
281
+ },
282
+ "body"=>{
283
+ "nullifiable"=>true,
284
+ "multiple"=>false,
285
+ "description"=>"Issue body.",
286
+ "options"=>nil,
287
+ "default"=>"",
288
+ "type"=>"string",
289
+ "minlen"=>nil,
290
+ "maxlen"=>nil,
291
+ "pattern"=>nil
292
+ },
293
+ "labels"=>{
294
+ "nullifiable"=>true,
295
+ "multiple"=>true,
296
+ "description"=>"Labels to associate with this issue.",
297
+ "options"=>{
298
+ "label_1"=>"Java",
299
+ "label_2"=>"Ruby",
300
+ "label_3"=>"Elixir"
301
+ },
302
+ "default"=>"",
303
+ "type"=>"string",
304
+ "minlen"=>nil,
305
+ "maxlen"=>nil,
306
+ "pattern"=>nil
307
+ }
308
+ },
309
+ "example"=>{
310
+ "title"=>"Found a bug",
311
+ "body"=>"I'm having a problem with this.",
312
+ "labels"=>[
313
+ "label_1",
314
+ "label_2"
315
+ ]
316
+ }
317
+ },
318
+ "DELETE"=>{
319
+ "title"=>"Delete issues",
320
+ "description"=>"Remove every issues.",
321
+ "query_string"=>{},
322
+ "parameters"=>{},
323
+ "example"=>nil
324
+ }
325
+ })
326
+ end
327
+ end
328
+
329
+ describe '#valid?' do
330
+ it 'MUST valid the Ruby object o to a Opushon string' do
331
+ options_issues.valid?(:POST, {
332
+ "title" => "Found a bug",
333
+ "body" => "I'm having a problem with this.",
334
+ "labels" => [
335
+ "label_1",
336
+ "label_2"
337
+ ]
338
+ }).must_equal(true)
339
+ end
340
+ end
341
+ end
342
+
343
+ describe '.dump' do
344
+ it 'MUST dump Ruby object o to a Opushon string' do
345
+ Opushon.dump({
346
+ DELETE: {
347
+ title: 'Delete issues',
348
+ description: 'Remove every issues.'
349
+ }
350
+ }).must_equal('{"DELETE":{"title":"Delete issues","description":"Remove every issues."}}')
351
+ end
352
+ end
353
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative 'support'
4
+ require_relative File.join(*%w(.. lib opushon))
@@ -0,0 +1,9 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+
9
+ SimpleCov.start
@@ -0,0 +1 @@
1
+ abort "Needs Ruby 2, you're running: #{RUBY_VERSION}" if RUBY_VERSION < '2'
@@ -0,0 +1,15 @@
1
+ class Object
2
+ alias_method :overridden_initialize, :initialize
3
+
4
+ def initialize
5
+ overridden_initialize
6
+
7
+ if !self.class.ancestors.include?(SimpleCov::Formatter::MultiFormatter) &&
8
+ !self.class.ancestors.include?(SimpleCov::Formatter::HTMLFormatter) &&
9
+ !self.class.ancestors.include?(Minitest::CompositeReporter) &&
10
+ !self.class.ancestors.include?(Minitest::SummaryReporter) &&
11
+ !self.class.ancestors.include?(Minitest::ProgressReporter)
12
+ freeze
13
+ end
14
+ end
15
+ end
data/spec/support.rb ADDED
@@ -0,0 +1,3 @@
1
+ Dir[File.join File.dirname(__FILE__), 'support', '**' '*.rb'].each do |filename|
2
+ require_relative filename
3
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opushon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Wack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ description: An Opushon's body parser and emitter.
84
+ email:
85
+ - contact@cyril.email
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".coveralls.yml"
91
+ - ".gitignore"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.md
96
+ - README.md
97
+ - Rakefile
98
+ - VERSION.semver
99
+ - lib/opushon.rb
100
+ - lib/opushon/attribute.rb
101
+ - lib/opushon/error.rb
102
+ - lib/opushon/error/base_error.rb
103
+ - lib/opushon/error/syntax_error.rb
104
+ - lib/opushon/error/verb_error.rb
105
+ - lib/opushon/instance.rb
106
+ - lib/opushon/option.rb
107
+ - lib/opushon/option_object.rb
108
+ - lib/opushon/type.rb
109
+ - lib/opushon/type/base.rb
110
+ - lib/opushon/type/boolean.rb
111
+ - lib/opushon/type/number.rb
112
+ - lib/opushon/type/string.rb
113
+ - lib/opushon/verb.rb
114
+ - lib/opushon/verb/base.rb
115
+ - lib/opushon/verb/delete.rb
116
+ - lib/opushon/verb/get.rb
117
+ - lib/opushon/verb/head.rb
118
+ - lib/opushon/verb/patch.rb
119
+ - lib/opushon/verb/post.rb
120
+ - lib/opushon/verb/put.rb
121
+ - lib/opushon/version.rb
122
+ - opushon.gemspec
123
+ - spec/opushon/spec_helper.rb
124
+ - spec/opushon/version_spec.rb
125
+ - spec/opushon_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/support.rb
128
+ - spec/support/coverage.rb
129
+ - spec/support/env.rb
130
+ - spec/support/immutable.rb
131
+ homepage: https://github.com/cyril/opushon.rb
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 2.0.0
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.4.4
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: A HTTP Opushon parser and emitter
155
+ test_files:
156
+ - spec/opushon/spec_helper.rb
157
+ - spec/opushon/version_spec.rb
158
+ - spec/opushon_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support.rb
161
+ - spec/support/coverage.rb
162
+ - spec/support/env.rb
163
+ - spec/support/immutable.rb
164
+ has_rdoc: