pliny 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny/commands/generator/schema.rb +55 -5
- data/lib/pliny/errors.rb +2 -0
- data/lib/pliny/templates/endpoint_scaffold_acceptance_test.erb +5 -5
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +1 -1
- data/lib/template/{docs/schema → schema}/meta.json +0 -0
- data/lib/template/{docs/schema → schema}/schemata/.gitkeep +0 -0
- data/spec/commands/generator/schema_spec.rb +73 -0
- data/spec/commands/generator_spec.rb +3 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d36f4a628a9157de2ecfa657662a5a638944e2f
|
4
|
+
data.tar.gz: 5c5f671fec1d136e0968bdfe8b6b743fec540d36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acea4ff673529b2218632bf1e44711cc3d998e24d2134fbb38859509494388f571cac7e7842d0fa0acdc18ed775ee05e907ecfada795d4d5bb9381d3d10df11c
|
7
|
+
data.tar.gz: a2bdb510b4ae82de58cf6ea001a0dce1dc0d1474695c6e0a2a185bd7a4ca669eca4c7ee1c2b6fdb43b00eae7534a4f2c7c5f6b898ae85cbb85297f864fb6283d
|
@@ -4,8 +4,15 @@ require 'prmd'
|
|
4
4
|
module Pliny::Commands
|
5
5
|
class Generator
|
6
6
|
class Schema < Base
|
7
|
+
def initialize(*)
|
8
|
+
super
|
9
|
+
@warned_legacy = false
|
10
|
+
end
|
11
|
+
|
7
12
|
def create
|
8
|
-
|
13
|
+
warn_legacy if legacy?
|
14
|
+
|
15
|
+
schema = schema_yaml_path(field_name)
|
9
16
|
write_file(schema) do
|
10
17
|
Prmd.init(name.singularize, yaml: true)
|
11
18
|
end
|
@@ -13,11 +20,54 @@ module Pliny::Commands
|
|
13
20
|
end
|
14
21
|
|
15
22
|
def rebuild
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
warn_legacy if legacy?
|
24
|
+
|
25
|
+
write_file(schema_json_path) do
|
26
|
+
Prmd.combine(schemata_path, meta: meta_path)
|
27
|
+
end
|
28
|
+
display "rebuilt #{schema_json_path}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def legacy?
|
32
|
+
File.exist?("./docs/schema.json") || File.directory?("./docs/schema/schemata")
|
33
|
+
end
|
34
|
+
|
35
|
+
def warn_legacy
|
36
|
+
return if @warned_legacy
|
37
|
+
display "WARNING: Using legacy schema layout under docs/. To use new layout under schema/, run `mkdir -p schema && git mv docs/schema.json docs/schema/meta.* docs/schema/schemata schema` then check for remaining schema-related files under docs/."
|
38
|
+
@warned_legacy = true
|
39
|
+
end
|
40
|
+
|
41
|
+
def schema_json_path
|
42
|
+
if legacy?
|
43
|
+
"./docs/schema.json"
|
44
|
+
else
|
45
|
+
"./schema/schema.json"
|
19
46
|
end
|
20
|
-
|
47
|
+
end
|
48
|
+
|
49
|
+
def meta_path
|
50
|
+
if legacy?
|
51
|
+
"./docs/schema/meta.json"
|
52
|
+
else
|
53
|
+
"./schema/meta.json"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def schemata_path
|
58
|
+
if legacy?
|
59
|
+
"./docs/schema/schemata"
|
60
|
+
else
|
61
|
+
"./schema/schemata"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def schema_base
|
66
|
+
Pathname.new("./schema")
|
67
|
+
end
|
68
|
+
|
69
|
+
def schema_yaml_path(field_name)
|
70
|
+
File.join(schemata_path, "#{field_name}.yaml")
|
21
71
|
end
|
22
72
|
end
|
23
73
|
end
|
data/lib/pliny/errors.rb
CHANGED
@@ -62,6 +62,7 @@ module Pliny
|
|
62
62
|
class RequestedRangeNotSatisfiable < HTTPStatusError; end # 416
|
63
63
|
class ExpectationFailed < HTTPStatusError; end # 417
|
64
64
|
class UnprocessableEntity < HTTPStatusError; end # 422
|
65
|
+
class TooManyRequests < HTTPStatusError; end # 429
|
65
66
|
class InternalServerError < HTTPStatusError; end # 500
|
66
67
|
class NotImplemented < HTTPStatusError; end # 501
|
67
68
|
class BadGateway < HTTPStatusError; end # 502
|
@@ -105,6 +106,7 @@ module Pliny
|
|
105
106
|
RequestedRangeNotSatisfiable => [416, 'Requested range not satisfiable'],
|
106
107
|
ExpectationFailed => [417, 'Expectation failed'],
|
107
108
|
UnprocessableEntity => [422, 'Unprocessable entity'],
|
109
|
+
TooManyRequests => [429, 'Too many requests'],
|
108
110
|
InternalServerError => [500, 'Internal server error'],
|
109
111
|
NotImplemented => [501, 'Not implemented'],
|
110
112
|
BadGateway => [502, 'Bad gateway'],
|
@@ -23,7 +23,7 @@ describe Endpoints::<%= plural_class_name %> do
|
|
23
23
|
describe 'GET <%= url_path %>' do
|
24
24
|
it 'returns correct status code and conforms to schema' do
|
25
25
|
get '<%= url_path %>'
|
26
|
-
|
26
|
+
assert_equal 200, last_response.status
|
27
27
|
assert_schema_conform
|
28
28
|
end
|
29
29
|
end
|
@@ -33,7 +33,7 @@ describe Endpoints::<%= plural_class_name %> do
|
|
33
33
|
it 'returns correct status code and conforms to schema' do
|
34
34
|
header "Content-Type", "application/json"
|
35
35
|
post '<%= url_path %>', MultiJson.encode({})
|
36
|
-
|
36
|
+
assert_equal 201, last_response.status
|
37
37
|
assert_schema_conform
|
38
38
|
end
|
39
39
|
end
|
@@ -42,7 +42,7 @@ describe Endpoints::<%= plural_class_name %> do
|
|
42
42
|
describe 'GET <%= url_path %>/:id' do
|
43
43
|
it 'returns correct status code and conforms to schema' do
|
44
44
|
get "<%= url_path %>/#{@<%= field_name %>.uuid}"
|
45
|
-
|
45
|
+
assert_equal 200, last_response.status
|
46
46
|
assert_schema_conform
|
47
47
|
end
|
48
48
|
end
|
@@ -51,7 +51,7 @@ describe Endpoints::<%= plural_class_name %> do
|
|
51
51
|
it 'returns correct status code and conforms to schema' do
|
52
52
|
header "Content-Type", "application/json"
|
53
53
|
patch "<%= url_path %>/#{@<%= field_name %>.uuid}", MultiJson.encode({})
|
54
|
-
|
54
|
+
assert_equal 200, last_response.status
|
55
55
|
assert_schema_conform
|
56
56
|
end
|
57
57
|
end
|
@@ -59,7 +59,7 @@ describe Endpoints::<%= plural_class_name %> do
|
|
59
59
|
describe 'DELETE <%= url_path %>/:id' do
|
60
60
|
it 'returns correct status code and conforms to schema' do
|
61
61
|
delete "<%= url_path %>/#{@<%= field_name %>.uuid}"
|
62
|
-
|
62
|
+
assert_equal 200, last_response.status
|
63
63
|
assert_schema_conform
|
64
64
|
end
|
65
65
|
end
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
File without changes
|
File without changes
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'pliny/commands/generator'
|
2
|
+
require 'pliny/commands/generator/schema'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Pliny::Commands::Generator::Schema do
|
6
|
+
let(:stream) { StringIO.new }
|
7
|
+
subject { Pliny::Commands::Generator::Schema.new('artist', {}, stream) }
|
8
|
+
|
9
|
+
around do |example|
|
10
|
+
Dir.mktmpdir do |dir|
|
11
|
+
app_dir = File.join(dir, "app")
|
12
|
+
# schema work depends on files seeded by the template
|
13
|
+
Pliny::Commands::Creator.run([app_dir], {}, StringIO.new)
|
14
|
+
Dir.chdir(app_dir, &example)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#create' do
|
19
|
+
context 'with new layout' do
|
20
|
+
before do
|
21
|
+
subject.create
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'creates a schema' do
|
25
|
+
assert File.exist?('schema/schemata/artist.yaml')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with legacy layout' do
|
30
|
+
before do
|
31
|
+
FileUtils.mkdir_p('./docs/schema/schemata')
|
32
|
+
FileUtils.cp('./schema/meta.json', './docs/schema')
|
33
|
+
subject.create
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'creates a legacy schema' do
|
37
|
+
assert File.exist?('docs/schema/schemata/artist.yaml')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'warns' do
|
41
|
+
assert_match(/WARNING/m, stream.string)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#rebuild' do
|
47
|
+
context 'with new layout' do
|
48
|
+
before do
|
49
|
+
subject.rebuild
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'rebuilds schema.json' do
|
53
|
+
assert File.exist?('./schema/schema.json')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with legacy layout' do
|
58
|
+
before do
|
59
|
+
FileUtils.mkdir_p('./docs/schema/schemata')
|
60
|
+
FileUtils.cp('./schema/meta.json', './docs/schema')
|
61
|
+
subject.rebuild
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'rebuilds legacy schema.json' do
|
65
|
+
assert File.exist?('docs/schema.json')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'warns' do
|
69
|
+
assert_match(/WARNING/m, stream.string)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -4,7 +4,7 @@ require 'pliny/commands/generator/base'
|
|
4
4
|
require 'spec_helper'
|
5
5
|
|
6
6
|
describe Pliny::Commands::Generator do
|
7
|
-
subject { Pliny::Commands::Generator.new }
|
7
|
+
subject { Pliny::Commands::Generator.new }
|
8
8
|
|
9
9
|
before do
|
10
10
|
Timecop.freeze(@t = Time.now)
|
@@ -127,7 +127,7 @@ subject { Pliny::Commands::Generator.new }
|
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'creates a schema' do
|
130
|
-
assert File.exist?('
|
130
|
+
assert File.exist?('schema/schemata/artist.yaml')
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'creates a new serializer module' do
|
@@ -145,7 +145,7 @@ subject { Pliny::Commands::Generator.new }
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'creates a schema' do
|
148
|
-
assert File.exist?('
|
148
|
+
assert File.exist?('schema/schemata/artist.yaml')
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -395,8 +395,6 @@ files:
|
|
395
395
|
- lib/template/config/puma.rb
|
396
396
|
- lib/template/db/schema.sql
|
397
397
|
- lib/template/db/seeds.rb
|
398
|
-
- lib/template/docs/schema/meta.json
|
399
|
-
- lib/template/docs/schema/schemata/.gitkeep
|
400
398
|
- lib/template/lib/application.rb
|
401
399
|
- lib/template/lib/endpoints/base.rb
|
402
400
|
- lib/template/lib/endpoints/root.rb
|
@@ -405,12 +403,15 @@ files:
|
|
405
403
|
- lib/template/lib/routes.rb
|
406
404
|
- lib/template/lib/serializers/base.rb
|
407
405
|
- lib/template/lib/tasks/spec.rake
|
406
|
+
- lib/template/schema/meta.json
|
407
|
+
- lib/template/schema/schemata/.gitkeep
|
408
408
|
- lib/template/spec/spec_helper.rb
|
409
409
|
- lib/template/spec/support/auto_define_rack_app.rb
|
410
410
|
- lib/template/spec/support/log.rb
|
411
411
|
- spec/commands/creator_spec.rb
|
412
412
|
- spec/commands/generator/base_spec.rb
|
413
413
|
- spec/commands/generator/endpoint_spec.rb
|
414
|
+
- spec/commands/generator/schema_spec.rb
|
414
415
|
- spec/commands/generator_spec.rb
|
415
416
|
- spec/errors_spec.rb
|
416
417
|
- spec/extensions/instruments_spec.rb
|
@@ -452,4 +453,3 @@ signing_key:
|
|
452
453
|
specification_version: 4
|
453
454
|
summary: Basic tooling to support API apps in Sinatra
|
454
455
|
test_files: []
|
455
|
-
has_rdoc:
|