pliny 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pliny-new +13 -4
- data/lib/pliny/commands/updater.rb +2 -2
- data/lib/pliny/config_helpers.rb +14 -0
- data/lib/pliny/db_support.rb +27 -8
- data/lib/pliny/errors.rb +1 -1
- data/lib/pliny/tasks/db.rake +13 -20
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +1 -1
- data/lib/template/db/seeds.rb +4 -1
- data/lib/template/lib/endpoints/base.rb +1 -3
- data/spec/db_support_spec.rb +18 -2
- data/spec/integration_spec.rb +15 -3
- data/spec/middleware/rescue_errors_spec.rb +0 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e0f67945b6d0c56fbc12eeeb1f05c27552d34ec
|
4
|
+
data.tar.gz: 0561658c246936f0e5aea4d84bb9594bf547901d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc4d4d529b7f99a29fad0261059bea8e038cb5e516fa1f6145d5c549b3e63d19801cbae9889ad30bf25eeec6073fcc35becf4fd190df4e05725e5db8cb3bfa28
|
7
|
+
data.tar.gz: b49455e9fe4a7d1064df6fa29903b35f6be59a297263ef6c3d90f3078a73603184ef1f2053cff12a28ea59a0f200989fde44b3384ff66e29891e7cc44f99c88d
|
data/bin/pliny-new
CHANGED
@@ -3,10 +3,19 @@
|
|
3
3
|
require "optparse"
|
4
4
|
require_relative '../lib/pliny/commands/creator'
|
5
5
|
|
6
|
-
|
6
|
+
OptionParser.new do |options|
|
7
7
|
opts = {}
|
8
|
+
options.banner = "Usage: pliny-new app-name [options]"
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
begin
|
11
|
+
options.parse!
|
12
|
+
if ARGV.empty?
|
13
|
+
puts options.banner
|
14
|
+
else
|
15
|
+
Pliny::Commands::Creator.run(ARGV.dup, opts)
|
16
|
+
end
|
17
|
+
rescue OptionParser::InvalidOption => e
|
18
|
+
puts e
|
19
|
+
puts options.banner
|
20
|
+
end
|
12
21
|
end
|
@@ -59,9 +59,9 @@ module Pliny::Commands
|
|
59
59
|
# take a diff of changes that happened to the template app in Pliny
|
60
60
|
diff = `cd #{repo_dir} && git diff v#{curr}..v#{target} lib/template/`
|
61
61
|
|
62
|
-
# remove lib/template from the path of files in the patch so that we can
|
62
|
+
# remove /lib/template from the path of files in the patch so that we can
|
63
63
|
# apply these to the current folder
|
64
|
-
diff.gsub!(
|
64
|
+
diff.gsub!(/(\w)\/lib\/template/, '\1')
|
65
65
|
|
66
66
|
File.open(patch_file, "w") { |f| f.puts diff }
|
67
67
|
end
|
data/lib/pliny/config_helpers.rb
CHANGED
@@ -35,6 +35,20 @@ module Pliny
|
|
35
35
|
->(v) { v.to_sym }
|
36
36
|
end
|
37
37
|
|
38
|
+
# optional :accronyms, array(string)
|
39
|
+
# => ['a', 'b']
|
40
|
+
# optional :numbers, array(int)
|
41
|
+
# => [1, 2]
|
42
|
+
# optional :notype, array
|
43
|
+
# => ['a', 'b']
|
44
|
+
def array(method = nil)
|
45
|
+
-> (v) do
|
46
|
+
if v
|
47
|
+
v.split(",").map{|a| cast(a, method) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
38
52
|
private
|
39
53
|
|
40
54
|
def cast(value, method)
|
data/lib/pliny/db_support.rb
CHANGED
@@ -4,27 +4,46 @@ require "sequel/extensions/migration"
|
|
4
4
|
|
5
5
|
module Pliny
|
6
6
|
class DbSupport
|
7
|
-
|
7
|
+
def self.admin_url(database_url)
|
8
|
+
uri = URI.parse(database_url)
|
9
|
+
uri.path = "/postgres"
|
10
|
+
uri.to_s
|
11
|
+
end
|
8
12
|
|
9
|
-
def self.
|
10
|
-
|
13
|
+
def self.setup?(database_url)
|
14
|
+
@db = Sequel.connect(database_url)
|
15
|
+
@db.test_connection
|
16
|
+
@db.disconnect
|
17
|
+
return true
|
18
|
+
rescue Sequel::DatabaseConnectionError
|
19
|
+
return false
|
11
20
|
end
|
12
21
|
|
13
|
-
def self.run(url)
|
14
|
-
|
22
|
+
def self.run(url, sequel_log_io=StringIO.new)
|
23
|
+
logger = Logger.new(sequel_log_io)
|
24
|
+
instance = new(url, logger)
|
15
25
|
yield instance
|
16
26
|
instance.disconnect
|
17
27
|
end
|
18
28
|
|
19
29
|
attr_accessor :db
|
20
30
|
|
21
|
-
def initialize(url)
|
31
|
+
def initialize(url, sequel_logger)
|
22
32
|
@db = Sequel.connect(url)
|
23
|
-
if
|
24
|
-
@db.loggers <<
|
33
|
+
if sequel_logger
|
34
|
+
@db.loggers << sequel_logger
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
38
|
+
def exists?(name)
|
39
|
+
res = db.fetch("SELECT 1 FROM pg_database WHERE datname = ?", name)
|
40
|
+
return res.count > 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def create(name)
|
44
|
+
db.run(%{CREATE DATABASE "#{name}"})
|
45
|
+
end
|
46
|
+
|
28
47
|
def migrate(target=nil)
|
29
48
|
Sequel::Migrator.apply(db, "./db/migrate", target)
|
30
49
|
end
|
data/lib/pliny/errors.rb
CHANGED
@@ -5,7 +5,7 @@ module Pliny
|
|
5
5
|
|
6
6
|
def self.render(error)
|
7
7
|
headers = { "Content-Type" => "application/json; charset=utf-8" }
|
8
|
-
data = { id: error.id, message: error.message
|
8
|
+
data = { id: error.id, message: error.message }
|
9
9
|
[error.status, headers, [MultiJson.encode(data)]]
|
10
10
|
end
|
11
11
|
|
data/lib/pliny/tasks/db.rake
CHANGED
@@ -6,14 +6,12 @@ require "uri"
|
|
6
6
|
require "pliny/db_support"
|
7
7
|
require "pliny/utils"
|
8
8
|
|
9
|
-
Pliny::DbSupport.logger = Logger.new($stdout)
|
10
|
-
|
11
9
|
namespace :db do
|
12
10
|
desc "Run database migrations"
|
13
11
|
task :migrate do
|
14
12
|
next if Dir["./db/migrate/*.rb"].empty?
|
15
13
|
database_urls.each do |database_url|
|
16
|
-
Pliny::DbSupport.run(database_url) do |helper|
|
14
|
+
Pliny::DbSupport.run(database_url, $stdout) do |helper|
|
17
15
|
helper.migrate
|
18
16
|
puts "Migrated `#{name_from_uri(database_url)}`"
|
19
17
|
end
|
@@ -24,7 +22,7 @@ namespace :db do
|
|
24
22
|
task :rollback do
|
25
23
|
next if Dir["./db/migrate/*.rb"].empty?
|
26
24
|
database_urls.each do |database_url|
|
27
|
-
Pliny::DbSupport.run(database_url) do |helper|
|
25
|
+
Pliny::DbSupport.run(database_url, $stdout) do |helper|
|
28
26
|
helper.rollback
|
29
27
|
puts "Rolled back `#{name_from_uri(database_url)}`"
|
30
28
|
end
|
@@ -45,16 +43,16 @@ namespace :db do
|
|
45
43
|
desc "Create the database"
|
46
44
|
task :create do
|
47
45
|
database_urls.each do |database_url|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
db_name = name_from_uri(database_url)
|
47
|
+
if Pliny::DbSupport.setup?(database_url)
|
48
|
+
puts "Skipping `#{db_name}`, already exists"
|
49
|
+
else
|
50
|
+
admin_url = Pliny::DbSupport.admin_url(database_url)
|
51
|
+
Pliny::DbSupport.run(admin_url) do |helper|
|
52
|
+
helper.create(db_name)
|
53
|
+
puts "Created `#{db_name}`"
|
54
|
+
end
|
56
55
|
end
|
57
|
-
puts "Created `#{name}`" if !exists
|
58
56
|
end
|
59
57
|
disconnect
|
60
58
|
end
|
@@ -62,7 +60,8 @@ namespace :db do
|
|
62
60
|
desc "Drop the database"
|
63
61
|
task :drop do
|
64
62
|
database_urls.each do |database_url|
|
65
|
-
|
63
|
+
admin_url = Pliny::DbSupport.admin_url(database_url)
|
64
|
+
db = Sequel.connect(admin_url)
|
66
65
|
name = name_from_uri(database_url)
|
67
66
|
db.run(%{DROP DATABASE IF EXISTS "#{name}"})
|
68
67
|
puts "Dropped `#{name}`"
|
@@ -146,10 +145,4 @@ namespace :db do
|
|
146
145
|
def name_from_uri(uri)
|
147
146
|
URI.parse(uri).path[1..-1]
|
148
147
|
end
|
149
|
-
|
150
|
-
def postgres_location_from_uri(uri)
|
151
|
-
p = URI.parse(uri)
|
152
|
-
p.path = ""
|
153
|
-
p.to_s
|
154
|
-
end
|
155
148
|
end
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
data/lib/template/db/seeds.rb
CHANGED
@@ -3,4 +3,7 @@
|
|
3
3
|
# The data can then be loaded with the rake db:seed (or created alongside the
|
4
4
|
# db with db:setup).
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# Seeding can occur multiple times during the execution of a single Rake task
|
7
|
+
# because seeding should occur in all environments (development, testing,
|
8
|
+
# etc.). The currently connected database can be accessed via
|
9
|
+
# `Sequel::DATABASES.last`.
|
data/spec/db_support_spec.rb
CHANGED
@@ -2,9 +2,11 @@ require "spec_helper"
|
|
2
2
|
require "pliny/db_support"
|
3
3
|
|
4
4
|
describe Pliny::DbSupport do
|
5
|
-
let(:
|
5
|
+
let(:url) { ENV["TEST_DATABASE_URL"] }
|
6
|
+
let(:logger) { Logger.new(StringIO.new) }
|
7
|
+
let(:support) { Pliny::DbSupport.new(url, logger) }
|
6
8
|
|
7
|
-
before
|
9
|
+
before do
|
8
10
|
@path = "/tmp/pliny-test"
|
9
11
|
end
|
10
12
|
|
@@ -15,6 +17,20 @@ describe Pliny::DbSupport do
|
|
15
17
|
Dir.chdir(@path)
|
16
18
|
end
|
17
19
|
|
20
|
+
describe ".admin_url" do
|
21
|
+
it "connects to the postgres system's db" do
|
22
|
+
assert_equal "postgres://1.2.3.4/postgres",
|
23
|
+
Pliny::DbSupport.admin_url("postgres://1.2.3.4/my-db")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".setup?" do
|
28
|
+
it "checks if the database is responsive" do
|
29
|
+
assert_equal true, Pliny::DbSupport.setup?(url)
|
30
|
+
assert_equal false, Pliny::DbSupport.setup?("postgres://localhost/does-not-exist")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
18
34
|
describe "#migrate" do
|
19
35
|
before do
|
20
36
|
File.open("#{@path}/db/migrate/#{Time.now.to_i}_create_foo.rb", "w") do |f|
|
data/spec/integration_spec.rb
CHANGED
@@ -16,14 +16,26 @@ describe "Pliny integration test" do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe "pliny-generate
|
19
|
+
describe "pliny-generate scaffold" do
|
20
20
|
before(:all) do
|
21
|
-
bash_app "pliny-generate
|
21
|
+
bash_app "pliny-generate scaffold artist"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "creates the model file" do
|
25
25
|
assert File.exists?("./myapp/lib/models/artist.rb")
|
26
26
|
end
|
27
|
+
|
28
|
+
it "creates the endpoint file" do
|
29
|
+
assert File.exists?("./myapp/lib/endpoints/artists.rb")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "creates the serializer file" do
|
33
|
+
assert File.exists?("./myapp/lib/serializers/artist.rb")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "creates the schema file" do
|
37
|
+
assert File.exists?("./myapp/schema/schemata/artist.yaml")
|
38
|
+
end
|
27
39
|
end
|
28
40
|
|
29
41
|
def bash(cmd)
|
@@ -38,4 +50,4 @@ describe "Pliny integration test" do
|
|
38
50
|
def bash_app(cmd)
|
39
51
|
bash "cd myapp && #{cmd}"
|
40
52
|
end
|
41
|
-
end
|
53
|
+
end
|
@@ -24,7 +24,6 @@ describe Pliny::Middleware::RescueErrors do
|
|
24
24
|
error_json = MultiJson.decode(last_response.body)
|
25
25
|
assert_equal "service_unavailable", error_json["id"]
|
26
26
|
assert_equal "Service unavailable.", error_json["message"]
|
27
|
-
assert_equal 503, error_json["status"]
|
28
27
|
end
|
29
28
|
|
30
29
|
it "intercepts exceptions and renders" do
|
@@ -34,7 +33,6 @@ describe Pliny::Middleware::RescueErrors do
|
|
34
33
|
error_json = MultiJson.decode(last_response.body)
|
35
34
|
assert_equal "internal_server_error", error_json["id"]
|
36
35
|
assert_equal "Internal server error.", error_json["message"]
|
37
|
-
assert_equal 500, error_json["status"]
|
38
36
|
end
|
39
37
|
|
40
38
|
it "raises given the raise option" do
|
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.11.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-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -474,7 +474,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
474
474
|
version: '0'
|
475
475
|
requirements: []
|
476
476
|
rubyforge_project:
|
477
|
-
rubygems_version: 2.4.
|
477
|
+
rubygems_version: 2.4.3
|
478
478
|
signing_key:
|
479
479
|
specification_version: 4
|
480
480
|
summary: Basic tooling to support API apps in Sinatra
|