pliny 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.
- checksums.yaml +14 -6
- data/README.md +59 -11
- data/bin/pliny-generate +2 -14
- data/bin/pliny-new +1 -1
- data/lib/pliny/commands/creator.rb +10 -11
- data/lib/pliny/commands/generator/base.rb +59 -0
- data/lib/pliny/commands/generator/endpoint.rb +44 -0
- data/lib/pliny/commands/generator/mediator.rb +21 -0
- data/lib/pliny/commands/generator/migration.rb +13 -0
- data/lib/pliny/commands/generator/model.rb +30 -0
- data/lib/pliny/commands/generator/schema.rb +24 -0
- data/lib/pliny/commands/generator/serializer.rb +21 -0
- data/lib/pliny/commands/generator.rb +50 -199
- data/lib/pliny/config_helpers.rb +52 -0
- data/lib/pliny/errors.rb +7 -4
- data/lib/pliny/helpers/encode.rb +7 -0
- data/lib/pliny/log.rb +18 -1
- data/lib/pliny/middleware/rescue_errors.rb +2 -8
- data/lib/pliny/middleware/versioning.rb +3 -3
- data/lib/pliny/tasks/db.rake +21 -7
- data/lib/pliny/tasks/schema.rake +2 -2
- data/lib/pliny/templates/endpoint.erb +5 -5
- data/lib/pliny/templates/endpoint_acceptance_test.erb +1 -1
- data/lib/pliny/templates/endpoint_scaffold.erb +5 -5
- data/lib/pliny/templates/endpoint_scaffold_acceptance_test.erb +1 -1
- data/lib/pliny/templates/endpoint_test.erb +1 -0
- data/lib/pliny/templates/migration.erb +0 -2
- data/lib/pliny/templates/model.erb +0 -2
- data/lib/pliny/templates/model_test.erb +0 -1
- data/lib/pliny/templates/serializer_test.erb +0 -1
- data/lib/pliny/version.rb +1 -1
- data/lib/pliny.rb +1 -2
- data/template/.env.sample +2 -1
- data/template/README.md +1 -1
- data/template/bin/console +1 -3
- data/template/bin/run +1 -3
- data/template/config/config.rb +19 -25
- data/template/config/initializers/rollbar.rb +1 -0
- data/template/config/puma.rb +2 -2
- data/template/config.ru +1 -4
- data/template/db/schema.sql +1 -2
- data/template/lib/application.rb +4 -0
- data/template/lib/endpoints/base.rb +5 -0
- data/template/lib/routes.rb +1 -1
- data/template/lib/serializers/base.rb +8 -1
- data/test/commands/creator_test.rb +1 -0
- data/test/commands/generator/base_test.rb +103 -0
- data/test/commands/generator/endpoint_test.rb +15 -0
- data/test/commands/generator_test.rb +95 -134
- data/test/extensions/instruments_test.rb +4 -0
- data/test/log_test.rb +16 -0
- metadata +116 -61
|
@@ -1,222 +1,73 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require "ostruct"
|
|
4
|
-
require "active_support/inflector"
|
|
5
|
-
require "prmd"
|
|
1
|
+
require 'pliny/version'
|
|
2
|
+
require 'thor'
|
|
6
3
|
|
|
7
4
|
module Pliny::Commands
|
|
8
|
-
class Generator
|
|
9
|
-
|
|
5
|
+
class Generator < Thor
|
|
6
|
+
desc 'endpoint NAME', 'Generates an endpoint'
|
|
7
|
+
method_option :scaffold, type: :boolean, default: false, hide: true
|
|
8
|
+
def endpoint(name)
|
|
9
|
+
require_relative 'generator/endpoint'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
ep = Endpoint.new(name, options)
|
|
12
|
+
ep.create
|
|
13
|
+
ep.create_test
|
|
14
|
+
ep.create_acceptance_test
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@stream = stream
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def run!
|
|
22
|
-
unless type
|
|
23
|
-
raise "Missing type of object to generate"
|
|
24
|
-
end
|
|
25
|
-
unless name
|
|
26
|
-
raise "Missing #{type} name"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
case type
|
|
30
|
-
when "endpoint"
|
|
31
|
-
create_endpoint(scaffold: false)
|
|
32
|
-
create_endpoint_test
|
|
33
|
-
create_endpoint_acceptance_test(scaffold: false)
|
|
34
|
-
when "mediator"
|
|
35
|
-
create_mediator
|
|
36
|
-
create_mediator_test
|
|
37
|
-
when "migration"
|
|
38
|
-
create_migration
|
|
39
|
-
when "model"
|
|
40
|
-
create_model
|
|
41
|
-
create_model_migration
|
|
42
|
-
create_model_test
|
|
43
|
-
when "scaffold"
|
|
44
|
-
create_endpoint(scaffold: true)
|
|
45
|
-
create_endpoint_test
|
|
46
|
-
create_endpoint_acceptance_test(scaffold: true)
|
|
47
|
-
create_model
|
|
48
|
-
create_model_migration
|
|
49
|
-
create_model_test
|
|
50
|
-
create_schema
|
|
51
|
-
rebuild_schema
|
|
52
|
-
create_serializer
|
|
53
|
-
create_serializer_test
|
|
54
|
-
when "schema"
|
|
55
|
-
create_schema
|
|
56
|
-
rebuild_schema
|
|
57
|
-
when "serializer"
|
|
58
|
-
create_serializer
|
|
59
|
-
create_serializer_test
|
|
60
|
-
else
|
|
61
|
-
abort("Don't know how to generate '#{type}'.")
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def type
|
|
66
|
-
args.first
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def name
|
|
70
|
-
args[1]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def paranoid
|
|
74
|
-
opts[:paranoid]
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def singular_class_name
|
|
78
|
-
name.gsub(/-/, '_').singularize.camelize
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def plural_class_name
|
|
82
|
-
name.gsub(/-/, '_').pluralize.camelize
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def field_name
|
|
86
|
-
name.tableize.singularize
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def table_name
|
|
90
|
-
name.tableize
|
|
91
|
-
end
|
|
17
|
+
desc 'mediator NAME', 'Generates a mediator'
|
|
18
|
+
def mediator(name)
|
|
19
|
+
require_relative 'generator/mediator'
|
|
92
20
|
|
|
93
|
-
|
|
94
|
-
|
|
21
|
+
md = Mediator.new(name, options)
|
|
22
|
+
md.create
|
|
23
|
+
md.create_test
|
|
95
24
|
end
|
|
96
25
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
render_template(template, endpoint, {
|
|
101
|
-
plural_class_name: plural_class_name,
|
|
102
|
-
singular_class_name: singular_class_name,
|
|
103
|
-
field_name: field_name,
|
|
104
|
-
url_path: url_path,
|
|
105
|
-
})
|
|
106
|
-
display "created endpoint file #{endpoint}"
|
|
107
|
-
display "add the following to lib/routes.rb:"
|
|
108
|
-
display " mount Endpoints::#{plural_class_name}"
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def create_endpoint_test
|
|
112
|
-
test = "./spec/endpoints/#{table_name}_spec.rb"
|
|
113
|
-
render_template("endpoint_test.erb", test, {
|
|
114
|
-
plural_class_name: plural_class_name,
|
|
115
|
-
singular_class_name: singular_class_name,
|
|
116
|
-
url_path: url_path,
|
|
117
|
-
})
|
|
118
|
-
display "created test #{test}"
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def create_endpoint_acceptance_test(options = {})
|
|
122
|
-
test = "./spec/acceptance/#{table_name}_spec.rb"
|
|
123
|
-
template = options[:scaffold] ? "endpoint_scaffold_acceptance_test.erb" :
|
|
124
|
-
"endpoint_acceptance_test.erb"
|
|
125
|
-
render_template(template, test, {
|
|
126
|
-
plural_class_name: plural_class_name,
|
|
127
|
-
field_name: field_name,
|
|
128
|
-
singular_class_name: singular_class_name,
|
|
129
|
-
url_path: url_path,
|
|
130
|
-
})
|
|
131
|
-
display "created test #{test}"
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def create_mediator
|
|
135
|
-
mediator = "./lib/mediators/#{field_name}.rb"
|
|
136
|
-
render_template("mediator.erb", mediator, singular_class_name: singular_class_name)
|
|
137
|
-
display "created mediator file #{mediator}"
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def create_mediator_test
|
|
141
|
-
test = "./spec/mediators/#{field_name}_spec.rb"
|
|
142
|
-
render_template("mediator_test.erb", test, singular_class_name: singular_class_name)
|
|
143
|
-
display "created test #{test}"
|
|
144
|
-
end
|
|
26
|
+
desc 'migration NAME', 'Generates a migration'
|
|
27
|
+
def migration(name)
|
|
28
|
+
require_relative 'generator/migration'
|
|
145
29
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
render_template("migration.erb", migration)
|
|
149
|
-
display "created migration #{migration}"
|
|
30
|
+
mg = Migration.new(name, options)
|
|
31
|
+
mg.create
|
|
150
32
|
end
|
|
151
33
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
paranoid: paranoid)
|
|
157
|
-
display "created model file #{model}"
|
|
158
|
-
end
|
|
34
|
+
desc 'model NAME', 'Generates a model'
|
|
35
|
+
method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model'
|
|
36
|
+
def model(name)
|
|
37
|
+
require_relative 'generator/model'
|
|
159
38
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
paranoid: paranoid)
|
|
165
|
-
display "created migration #{migration}"
|
|
39
|
+
md = Model.new(name, options)
|
|
40
|
+
md.create
|
|
41
|
+
md.create_migration
|
|
42
|
+
md.create_test
|
|
166
43
|
end
|
|
167
44
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
45
|
+
desc 'scaffold NAME', 'Generates a scaffold of endpoint, model, schema and serializer'
|
|
46
|
+
method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model'
|
|
47
|
+
method_option :scaffold, type: :boolean, default: true, hide: true
|
|
48
|
+
def scaffold(name)
|
|
49
|
+
endpoint(name)
|
|
50
|
+
model(name)
|
|
51
|
+
schema(name)
|
|
52
|
+
serializer(name)
|
|
172
53
|
end
|
|
173
54
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
Prmd.init(name.singularize, yaml: true)
|
|
178
|
-
end
|
|
179
|
-
display "created schema file #{schema}"
|
|
180
|
-
end
|
|
55
|
+
desc 'schema NAME', 'Generates a schema'
|
|
56
|
+
def schema(name)
|
|
57
|
+
require_relative 'generator/schema'
|
|
181
58
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
Prmd.combine("./docs/schema/schemata", meta: "./docs/schema/meta.json")
|
|
186
|
-
end
|
|
187
|
-
display "rebuilt #{schemata}"
|
|
59
|
+
sc = Schema.new(name, options)
|
|
60
|
+
sc.create
|
|
61
|
+
sc.rebuild
|
|
188
62
|
end
|
|
189
63
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
display "created serializer file #{serializer}"
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def create_serializer_test
|
|
197
|
-
test = "./spec/serializers/#{name}_serializer_spec.rb"
|
|
198
|
-
render_template("serializer_test.erb", test, singular_class_name: singular_class_name)
|
|
199
|
-
display "created test #{test}"
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
def render_template(template_file, destination_path, vars={})
|
|
203
|
-
template_path = File.dirname(__FILE__) + "/../templates/#{template_file}"
|
|
204
|
-
template = ERB.new(File.read(template_path), 0, ">")
|
|
205
|
-
context = OpenStruct.new(vars)
|
|
206
|
-
write_file(destination_path) do
|
|
207
|
-
template.result(context.instance_eval { binding })
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def url_path
|
|
212
|
-
"/" + name.pluralize.gsub(/_/, '-')
|
|
213
|
-
end
|
|
64
|
+
desc 'serializer NAME', 'Generates a serializer'
|
|
65
|
+
def serializer(name)
|
|
66
|
+
require_relative 'generator/serializer'
|
|
214
67
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
f.puts yield
|
|
219
|
-
end
|
|
68
|
+
se = Serializer.new(name, options)
|
|
69
|
+
se.create
|
|
70
|
+
se.create_test
|
|
220
71
|
end
|
|
221
72
|
end
|
|
222
73
|
end
|
data/lib/pliny/config_helpers.rb
CHANGED
|
@@ -1,4 +1,55 @@
|
|
|
1
1
|
module Pliny
|
|
2
|
+
module CastingConfigHelpers
|
|
3
|
+
def mandatory(name, method=nil)
|
|
4
|
+
value = cast(ENV.fetch(name.to_s.upcase), method)
|
|
5
|
+
create(name, value)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def optional(name, method=nil)
|
|
9
|
+
value = cast(ENV[name.to_s.upcase], method)
|
|
10
|
+
create(name, value)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def override(name, default, method=nil)
|
|
14
|
+
value = cast(ENV.fetch(name.to_s.upcase, default), method)
|
|
15
|
+
create(name, value)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def int
|
|
19
|
+
->(v) { v.to_i }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def float
|
|
23
|
+
->(v) { v.to_f }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def bool
|
|
27
|
+
->(v) { v.to_s=='true'}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def string
|
|
31
|
+
nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def symbol
|
|
35
|
+
->(v) { v.to_sym }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def cast(value, method)
|
|
41
|
+
method ? method.call(value) : value
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def create(name, value)
|
|
45
|
+
instance_variable_set(:"@#{name}", value)
|
|
46
|
+
instance_eval "def #{name}; @#{name} end", __FILE__, __LINE__
|
|
47
|
+
if value.kind_of?(TrueClass) || value.kind_of?(FalseClass) || value.kind_of?(NilClass)
|
|
48
|
+
instance_eval "def #{name}?; !!@#{name} end", __FILE__, __LINE__
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
2
53
|
module ConfigHelpers
|
|
3
54
|
def optional(*attrs)
|
|
4
55
|
attrs.each do |attr|
|
|
@@ -28,6 +79,7 @@ module Pliny
|
|
|
28
79
|
end
|
|
29
80
|
end
|
|
30
81
|
end
|
|
82
|
+
|
|
31
83
|
end
|
|
32
84
|
|
|
33
85
|
# Supress the "use RbConfig instead" warning.
|
data/lib/pliny/errors.rb
CHANGED
|
@@ -3,6 +3,12 @@ module Pliny
|
|
|
3
3
|
class Error < StandardError
|
|
4
4
|
attr_accessor :id
|
|
5
5
|
|
|
6
|
+
def self.render(error)
|
|
7
|
+
headers = { "Content-Type" => "application/json; charset=utf-8" }
|
|
8
|
+
data = { id: error.id, message: error.message, status: error.status }
|
|
9
|
+
[error.status, headers, [MultiJson.encode(data)]]
|
|
10
|
+
end
|
|
11
|
+
|
|
6
12
|
def initialize(message, id)
|
|
7
13
|
@id = id
|
|
8
14
|
super(message)
|
|
@@ -10,10 +16,7 @@ module Pliny
|
|
|
10
16
|
end
|
|
11
17
|
|
|
12
18
|
class HTTPStatusError < Error
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# so that Sinatra respects are status code when catching an exception
|
|
16
|
-
alias :http_status :status
|
|
19
|
+
attr_accessor :status
|
|
17
20
|
|
|
18
21
|
def initialize(message = nil, id = nil, status = nil)
|
|
19
22
|
meta = Pliny::Errors::META[self.class]
|
data/lib/pliny/log.rb
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
module Pliny
|
|
2
2
|
module Log
|
|
3
3
|
def log(data, &block)
|
|
4
|
-
data = log_context.merge(data)
|
|
4
|
+
data = log_context.merge(local_context.merge(data))
|
|
5
5
|
log_to_stream(stdout || $stdout, data, &block)
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
def context(data, &block)
|
|
9
|
+
old = local_context
|
|
10
|
+
self.local_context = old.merge(data)
|
|
11
|
+
res = block.call
|
|
12
|
+
ensure
|
|
13
|
+
local_context = old
|
|
14
|
+
res
|
|
15
|
+
end
|
|
16
|
+
|
|
8
17
|
def stdout=(stream)
|
|
9
18
|
@stdout = stream
|
|
10
19
|
end
|
|
@@ -15,6 +24,14 @@ module Pliny
|
|
|
15
24
|
|
|
16
25
|
private
|
|
17
26
|
|
|
27
|
+
def local_context
|
|
28
|
+
RequestStore.store[:local_context] ||= {}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def local_context=(h)
|
|
32
|
+
RequestStore.store[:local_context] = h
|
|
33
|
+
end
|
|
34
|
+
|
|
18
35
|
def log_context
|
|
19
36
|
RequestStore.store[:log_context] || {}
|
|
20
37
|
end
|
|
@@ -8,13 +8,13 @@ module Pliny::Middleware
|
|
|
8
8
|
def call(env)
|
|
9
9
|
@app.call(env)
|
|
10
10
|
rescue Pliny::Errors::Error => e
|
|
11
|
-
render(e
|
|
11
|
+
Pliny::Errors::Error.render(e)
|
|
12
12
|
rescue Exception => e
|
|
13
13
|
if @raise
|
|
14
14
|
raise
|
|
15
15
|
else
|
|
16
16
|
dump_error(e, env)
|
|
17
|
-
render(Pliny::Errors::InternalServerError.new
|
|
17
|
+
Pliny::Errors::Error.render(Pliny::Errors::InternalServerError.new)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -25,11 +25,5 @@ module Pliny::Middleware
|
|
|
25
25
|
message = ["#{e.class} - #{e.message}:", *e.backtrace].join("\n\t")
|
|
26
26
|
env['rack.errors'].puts(message)
|
|
27
27
|
end
|
|
28
|
-
|
|
29
|
-
def render(e, env)
|
|
30
|
-
headers = { "Content-Type" => "application/json; charset=utf-8" }
|
|
31
|
-
error = { id: e.id, message: e.message, status: e.status }
|
|
32
|
-
[e.status, headers, [MultiJson.encode(error)]]
|
|
33
|
-
end
|
|
34
28
|
end
|
|
35
29
|
end
|
|
@@ -22,7 +22,7 @@ module Pliny::Middleware
|
|
|
22
22
|
version = nil
|
|
23
23
|
media_types.map! do |media_type|
|
|
24
24
|
if accept_headers.include?(media_type.format)
|
|
25
|
-
|
|
25
|
+
unless media_type.params['version']
|
|
26
26
|
error = { id: :bad_version, message: <<-eos }
|
|
27
27
|
Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`.
|
|
28
28
|
eos
|
|
@@ -30,7 +30,7 @@ Please specify a version along with the MIME type. For example, `Accept: applica
|
|
|
30
30
|
[MultiJson.encode(error)]]
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
unless version
|
|
34
34
|
version = media_type.params["version"]
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -41,7 +41,7 @@ Please specify a version along with the MIME type. For example, `Accept: applica
|
|
|
41
41
|
end
|
|
42
42
|
media_type.to_s
|
|
43
43
|
end
|
|
44
|
-
env[
|
|
44
|
+
env['HTTP_ACCEPT'] = media_types.join(', ')
|
|
45
45
|
|
|
46
46
|
version ||= @default
|
|
47
47
|
set_api_version(env, version)
|
data/lib/pliny/tasks/db.rake
CHANGED
|
@@ -78,19 +78,33 @@ namespace :db do
|
|
|
78
78
|
namespace :schema do
|
|
79
79
|
desc "Load the database schema"
|
|
80
80
|
task :load do
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
if File.exists?("./db/schema.sql")
|
|
82
|
+
schema = File.read("./db/schema.sql")
|
|
83
|
+
database_urls.each do |database_url|
|
|
84
|
+
db = Sequel.connect(database_url)
|
|
85
|
+
db.run(schema)
|
|
86
|
+
puts "Loaded `#{name_from_uri(database_url)}`"
|
|
87
|
+
end
|
|
88
|
+
else
|
|
89
|
+
puts "Skipped schema load, schema.sql not present"
|
|
86
90
|
end
|
|
87
91
|
end
|
|
88
92
|
|
|
89
93
|
desc "Dump the database schema"
|
|
90
94
|
task :dump do
|
|
95
|
+
file = File.join("db", "schema.sql")
|
|
91
96
|
database_url = database_urls.first
|
|
92
|
-
`pg_dump -i -s -x -O -f
|
|
93
|
-
|
|
97
|
+
`pg_dump -i -s -x -O -f #{file} #{database_url}`
|
|
98
|
+
|
|
99
|
+
schema = File.read(file)
|
|
100
|
+
# filter all COMMENT ON EXTENSION, only owners and the db
|
|
101
|
+
# superuser can execute these, making it impossible to just
|
|
102
|
+
# replay such statements in certain production databases
|
|
103
|
+
schema.gsub!(/^COMMENT ON EXTENSION.*\n/, "")
|
|
104
|
+
|
|
105
|
+
File.open(file, "w") { |f| f.puts schema }
|
|
106
|
+
|
|
107
|
+
puts "Dumped `#{name_from_uri(database_url)}` to #{file}"
|
|
94
108
|
end
|
|
95
109
|
|
|
96
110
|
desc "Merges migrations into schema and removes them"
|
data/lib/pliny/tasks/schema.rake
CHANGED
|
@@ -6,24 +6,24 @@ module Endpoints
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
get do
|
|
9
|
-
|
|
9
|
+
encode []
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
post do
|
|
13
13
|
status 201
|
|
14
|
-
|
|
14
|
+
encode {}
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
get "/:id" do
|
|
18
|
-
|
|
18
|
+
encode {}
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
patch "/:id" do |id|
|
|
22
|
-
|
|
22
|
+
encode {}
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
delete "/:id" do |id|
|
|
26
|
-
|
|
26
|
+
encode {}
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -20,7 +20,7 @@ describe Endpoints::<%= plural_class_name %> do
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
describe 'POST <%= url_path
|
|
23
|
+
describe 'POST <%= url_path %>' do
|
|
24
24
|
it 'returns correct status code and conforms to schema' do
|
|
25
25
|
header "Content-Type", "application/json"
|
|
26
26
|
post '<%= url_path %>', MultiJson.encode({})
|
|
@@ -6,7 +6,7 @@ module Endpoints
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
get do
|
|
9
|
-
|
|
9
|
+
encode serialize(<%= singular_class_name %>.all)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
post do
|
|
@@ -14,25 +14,25 @@ module Endpoints
|
|
|
14
14
|
<%= field_name %> = <%= singular_class_name %>.new(body_params)
|
|
15
15
|
<%= field_name %>.save
|
|
16
16
|
status 201
|
|
17
|
-
|
|
17
|
+
encode serialize(<%= field_name %>)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
get "/:id" do |id|
|
|
21
21
|
<%= field_name %> = <%= singular_class_name %>.first(uuid: id) || halt(404)
|
|
22
|
-
|
|
22
|
+
encode serialize(<%= field_name %>)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
patch "/:id" do |id|
|
|
26
26
|
<%= field_name %> = <%= singular_class_name %>.first(uuid: id) || halt(404)
|
|
27
27
|
# warning: not safe
|
|
28
28
|
#<%= field_name %>.update(body_params)
|
|
29
|
-
|
|
29
|
+
encode serialize(<%= field_name %>)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
delete "/:id" do |id|
|
|
33
33
|
<%= field_name %> = <%= singular_class_name %>.first(uuid: id) || halt(404)
|
|
34
34
|
<%= field_name %>.destroy
|
|
35
|
-
|
|
35
|
+
encode serialize(<%= field_name %>)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
private
|
|
@@ -29,7 +29,7 @@ describe Endpoints::<%= plural_class_name %> do
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
=begin
|
|
32
|
-
describe 'POST <%= url_path
|
|
32
|
+
describe 'POST <%= url_path %>' 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({})
|
data/lib/pliny/version.rb
CHANGED
data/lib/pliny.rb
CHANGED
|
@@ -2,10 +2,9 @@ require "multi_json"
|
|
|
2
2
|
require "sinatra/base"
|
|
3
3
|
|
|
4
4
|
require_relative "pliny/version"
|
|
5
|
-
require_relative "pliny/commands/creator"
|
|
6
|
-
require_relative "pliny/commands/generator"
|
|
7
5
|
require_relative "pliny/errors"
|
|
8
6
|
require_relative "pliny/extensions/instruments"
|
|
7
|
+
require_relative "pliny/helpers/encode"
|
|
9
8
|
require_relative "pliny/helpers/params"
|
|
10
9
|
require_relative "pliny/log"
|
|
11
10
|
require_relative "pliny/request_store"
|