pliny 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e0f67945b6d0c56fbc12eeeb1f05c27552d34ec
4
- data.tar.gz: 0561658c246936f0e5aea4d84bb9594bf547901d
3
+ metadata.gz: 15e8fffa3d46a900635fa060a7fd577a42e8ee90
4
+ data.tar.gz: 797a949412bc6f88afc4533fffbab5bc160d66ab
5
5
  SHA512:
6
- metadata.gz: fc4d4d529b7f99a29fad0261059bea8e038cb5e516fa1f6145d5c549b3e63d19801cbae9889ad30bf25eeec6073fcc35becf4fd190df4e05725e5db8cb3bfa28
7
- data.tar.gz: b49455e9fe4a7d1064df6fa29903b35f6be59a297263ef6c3d90f3078a73603184ef1f2053cff12a28ea59a0f200989fde44b3384ff66e29891e7cc44f99c88d
6
+ metadata.gz: 51e4c8d782819ab40293e3b2b41b9fcd392e2ead19465f87951bcdd885b9149350c6b49e453918fee945233f3be8e9f7a519281e61c3f752af93656451c99b05
7
+ data.tar.gz: 15485eccede81da5f81e667fb2f3867fb5a409610db0d08b32c0ac325a5e5b32d0e48e7ac7cfb8209814153566c68bc8d4d4661469001cf7f0b51d7dbc0d7176
data/README.md CHANGED
@@ -1,53 +1,35 @@
1
1
  # Pliny
2
2
 
3
- Opinionated template Sinatra app for writing excellent APIs in Ruby.
4
-
3
+ [![Gem version](http://img.shields.io/gem/v/pliny.svg)](https://rubygems.org/gems/pliny)
5
4
  [![Build Status](https://travis-ci.org/interagent/pliny.svg?branch=master)](https://travis-ci.org/interagent/pliny)
6
5
 
7
- It bundles some of the patterns we like to develop these apps:
8
-
9
- - Config: `ENV` wrapper for explicit defining what config vars are mandatory and optional
10
- - Endpoints: the Sinatra equivalent of a Rails Controller
11
- - Initializers: tiny files to configure libraries/etc (equivalent of Rails)
12
- - Mediators: plain ruby classes to manipulate models
13
- - Models: very thin wrappers around the database
14
-
15
- And gems/helpers to tie these together and support operations:
16
-
17
- - [CORS middleware](lib/pliny/middleware/cors.rb) to allow JS developers to consume your API
18
- - [Rollbar](https://www.rollbar.com/) for tracking exceptions
19
- - [Log helper](spec/log_spec.rb) that logs in [data format](https://www.youtube.com/watch?v=rpmc-wHFUBs) [to stdout](https://adam.heroku.com/past/2011/4/1/logs_are_streams_not_files)
20
- - [Mediators](http://brandur.org/mediator) to help encapsulate more complex interactions
21
- - [Rspec](https://github.com/rspec/rspec) for lean and fast testing
22
- - [Puma](http://puma.io/) as the web server, [configured for optimal performance on Heroku](lib/template/config/puma.rb)
23
- - [Rack-test](https://github.com/brynary/rack-test) to test the API endpoints
24
- - [Request IDs](lib/pliny/middleware/request_id.rb)
25
- - [RequestStore](http://brandur.org/antipatterns), thread safe option to store data with the current request
26
- - [Sequel](http://sequel.jeremyevans.net/) for ORM
27
- - [Sequel-PG](https://github.com/jeremyevans/sequel_pg) to talk to the world's most advanced open source database
28
- - [Versioning](lib/pliny/middleware/versioning.rb) to allow versioning your API in the HTTP Accept header
6
+ Pliny helps Ruby developers write and maintain excellent APIs.
29
7
 
30
- ## Getting started
8
+ It bundles the best patterns, libraries and practices we've seen after writing a lot of APIs.
31
9
 
32
- First make sure the following is installed:
33
10
 
34
- * [Postgres](http://www.postgresql.org/)
35
- * The [uuid-ossp](http://www.postgresql.org/docs/9.3/static/uuid-ossp.html) module for Postgres
11
+ ## Resources
36
12
 
37
- Then install the gem:
13
+ - [Documentation](https://github.com/interagent/pliny/wiki)
14
+ - [Mailing list](https://groups.google.com/group/pliny-talk)
15
+
16
+
17
+ ## Getting started
18
+
19
+ Install gem:
38
20
 
39
21
  ```bash
40
22
  $ gem install pliny
41
23
  ```
42
24
 
43
- And initialize a new app:
25
+ And initialize your new API app:
44
26
 
45
27
  ```bash
46
28
  $ pliny-new myapp
47
29
  $ cd myapp && bin/setup
48
30
  ```
49
31
 
50
- Pliny also bundles [some generators](#generators) to help you get started:
32
+ Pliny bundles [generators](#generators) to help you get started:
51
33
 
52
34
  ```bash
53
35
  $ bundle exec pliny-generate model artist
@@ -106,13 +88,13 @@ Commands:
106
88
 
107
89
  ### Rake tasks
108
90
 
109
- Pliny comes with several rake tasks:
91
+ Pliny adds common Rake tasks to help maintain your app:
110
92
 
111
93
  ```bash
112
94
  rake db:create # Create the database
113
95
  rake db:drop # Drop the database
114
96
  rake db:migrate # Run database migrations
115
- rake db:rollback # Rollback the database
97
+ rake db:rollback # Rollback last database migration
116
98
  rake db:schema:dump # Dump the database schema
117
99
  rake db:schema:load # Load the database schema
118
100
  rake db:schema:merge # Merges migrations into schema and removes them
@@ -152,3 +134,5 @@ $ rake
152
134
  ## Meta
153
135
 
154
136
  Created by Brandur Leach and Pedro Belo.
137
+
138
+ MIT licensed.
@@ -3,9 +3,9 @@ require 'thor'
3
3
 
4
4
  module Pliny::Commands
5
5
  class Generator < Thor
6
- desc 'endpoint [NAME]', 'Generates an endpoint'
6
+ desc 'endpoint NAME', 'Generates an endpoint'
7
7
  method_option :scaffold, type: :boolean, default: false, hide: true
8
- def endpoint(*name)
8
+ def endpoint(name)
9
9
  require_relative 'generator/endpoint'
10
10
 
11
11
  ep = Endpoint.new(name, options)
@@ -14,8 +14,8 @@ module Pliny::Commands
14
14
  ep.create_acceptance_test
15
15
  end
16
16
 
17
- desc 'mediator [NAME]', 'Generates a mediator'
18
- def mediator(*name)
17
+ desc 'mediator NAME', 'Generates a mediator'
18
+ def mediator(name)
19
19
  require_relative 'generator/mediator'
20
20
 
21
21
  md = Mediator.new(name, options)
@@ -23,17 +23,17 @@ module Pliny::Commands
23
23
  md.create_test
24
24
  end
25
25
 
26
- desc 'migration [NAME]', 'Generates a migration'
27
- def migration(*name)
26
+ desc 'migration NAME', 'Generates a migration'
27
+ def migration(name)
28
28
  require_relative 'generator/migration'
29
29
 
30
30
  mg = Migration.new(name, options)
31
31
  mg.create
32
32
  end
33
33
 
34
- desc 'model [NAME]', 'Generates a model'
34
+ desc 'model NAME', 'Generates a model'
35
35
  method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model'
36
- def model(*name)
36
+ def model(name)
37
37
  require_relative 'generator/model'
38
38
 
39
39
  md = Model.new(name, options)
@@ -42,18 +42,18 @@ module Pliny::Commands
42
42
  md.create_test
43
43
  end
44
44
 
45
- desc 'scaffold [NAME]', 'Generates a scaffold of endpoint, model, schema and serializer'
45
+ desc 'scaffold NAME', 'Generates a scaffold of endpoint, model, schema and serializer'
46
46
  method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model'
47
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)
48
+ def scaffold(name)
49
+ endpoint(name)
50
+ model(name)
51
+ schema(name)
52
+ serializer(name)
53
53
  end
54
54
 
55
- desc 'schema [NAME]', 'Generates a schema'
56
- def schema(*name)
55
+ desc 'schema NAME', 'Generates a schema'
56
+ def schema(name)
57
57
  require_relative 'generator/schema'
58
58
 
59
59
  sc = Schema.new(name, options)
@@ -61,8 +61,8 @@ module Pliny::Commands
61
61
  sc.rebuild
62
62
  end
63
63
 
64
- desc 'serializer [NAME]', 'Generates a serializer'
65
- def serializer(*name)
64
+ desc 'serializer NAME', 'Generates a serializer'
65
+ def serializer(name)
66
66
  require_relative 'generator/serializer'
67
67
 
68
68
  se = Serializer.new(name, options)
@@ -62,9 +62,7 @@ module Pliny::Commands
62
62
  private
63
63
 
64
64
  def normalize_name(name)
65
- Array(name).map(&:underscore)
66
- .map { |n| n.tr(' ', '_') }
67
- .join('_')
65
+ name.underscore.tr(' ', '_')
68
66
  end
69
67
  end
70
68
  end
@@ -4,7 +4,7 @@ module Pliny::Middleware
4
4
  ALLOW_METHODS =
5
5
  %w( GET POST PUT PATCH DELETE OPTIONS ).freeze
6
6
  ALLOW_HEADERS =
7
- %w( * Content-Type Accept AUTHORIZATION Cache-Control ).freeze
7
+ %w( Content-Type Accept Authorization Cache-Control If-None-Match If-Modified-Since ).freeze
8
8
  EXPOSE_HEADERS =
9
9
  %w( Cache-Control Content-Language Content-Type Expires Last-Modified Pragma ).freeze
10
10
 
@@ -1,148 +1,153 @@
1
1
  require "logger"
2
- require "sequel"
3
- require "sequel/extensions/migration"
4
2
  require "uri"
5
-
6
- require "pliny/db_support"
7
3
  require "pliny/utils"
8
4
 
9
- namespace :db do
10
- desc "Run database migrations"
11
- task :migrate do
12
- next if Dir["./db/migrate/*.rb"].empty?
13
- database_urls.each do |database_url|
14
- Pliny::DbSupport.run(database_url, $stdout) do |helper|
15
- helper.migrate
16
- puts "Migrated `#{name_from_uri(database_url)}`"
5
+ begin
6
+ require "sequel"
7
+ require "sequel/extensions/migration"
8
+ require "pliny/db_support"
9
+
10
+ namespace :db do
11
+ desc "Run database migrations"
12
+ task :migrate do
13
+ next if Dir["./db/migrate/*.rb"].empty?
14
+ database_urls.each do |database_url|
15
+ Pliny::DbSupport.run(database_url, $stdout) do |helper|
16
+ helper.migrate
17
+ puts "Migrated `#{name_from_uri(database_url)}`"
18
+ end
17
19
  end
18
20
  end
19
- end
20
21
 
21
- desc "Rollback last database migration"
22
- task :rollback do
23
- next if Dir["./db/migrate/*.rb"].empty?
24
- database_urls.each do |database_url|
25
- Pliny::DbSupport.run(database_url, $stdout) do |helper|
26
- helper.rollback
27
- puts "Rolled back `#{name_from_uri(database_url)}`"
22
+ desc "Rollback last database migration"
23
+ task :rollback do
24
+ next if Dir["./db/migrate/*.rb"].empty?
25
+ database_urls.each do |database_url|
26
+ Pliny::DbSupport.run(database_url, $stdout) do |helper|
27
+ helper.rollback
28
+ puts "Rolled back `#{name_from_uri(database_url)}`"
29
+ end
28
30
  end
29
31
  end
30
- end
31
32
 
32
- desc "Seed the database with data"
33
- task :seed do
34
- if File.exist?('./db/seeds.rb')
35
- database_urls.each do |database_url|
36
- Sequel.connect(database_url)
37
- load 'db/seeds.rb'
33
+ desc "Seed the database with data"
34
+ task :seed do
35
+ if File.exist?('./db/seeds.rb')
36
+ database_urls.each do |database_url|
37
+ Sequel.connect(database_url)
38
+ load 'db/seeds.rb'
39
+ end
40
+ disconnect
38
41
  end
39
- disconnect
40
42
  end
41
- end
42
43
 
43
- desc "Create the database"
44
- task :create do
45
- database_urls.each do |database_url|
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}`"
44
+ desc "Create the database"
45
+ task :create do
46
+ database_urls.each do |database_url|
47
+ db_name = name_from_uri(database_url)
48
+ if Pliny::DbSupport.setup?(database_url)
49
+ puts "Skipping `#{db_name}`, already exists"
50
+ else
51
+ admin_url = Pliny::DbSupport.admin_url(database_url)
52
+ Pliny::DbSupport.run(admin_url) do |helper|
53
+ helper.create(db_name)
54
+ puts "Created `#{db_name}`"
55
+ end
54
56
  end
55
57
  end
58
+ disconnect
56
59
  end
57
- disconnect
58
- end
59
60
 
60
- desc "Drop the database"
61
- task :drop do
62
- database_urls.each do |database_url|
63
- admin_url = Pliny::DbSupport.admin_url(database_url)
64
- db = Sequel.connect(admin_url)
65
- name = name_from_uri(database_url)
66
- db.run(%{DROP DATABASE IF EXISTS "#{name}"})
67
- puts "Dropped `#{name}`"
61
+ desc "Drop the database"
62
+ task :drop do
63
+ database_urls.each do |database_url|
64
+ admin_url = Pliny::DbSupport.admin_url(database_url)
65
+ db = Sequel.connect(admin_url)
66
+ name = name_from_uri(database_url)
67
+ db.run(%{DROP DATABASE IF EXISTS "#{name}"})
68
+ puts "Dropped `#{name}`"
69
+ end
70
+ disconnect
68
71
  end
69
- disconnect
70
- end
71
72
 
72
- namespace :schema do
73
- desc "Load the database schema"
74
- task :load do
75
- if File.exists?("./db/schema.sql")
76
- schema = File.read("./db/schema.sql")
77
- database_urls.each do |database_url|
78
- db = Sequel.connect(database_url)
79
- db.run(schema)
80
- puts "Loaded `#{name_from_uri(database_url)}`"
73
+ namespace :schema do
74
+ desc "Load the database schema"
75
+ task :load do
76
+ if File.exists?("./db/schema.sql")
77
+ schema = File.read("./db/schema.sql")
78
+ database_urls.each do |database_url|
79
+ db = Sequel.connect(database_url)
80
+ db.run(schema)
81
+ puts "Loaded `#{name_from_uri(database_url)}`"
82
+ end
83
+ disconnect
84
+ else
85
+ puts "Skipped schema load, schema.sql not present"
81
86
  end
82
- disconnect
83
- else
84
- puts "Skipped schema load, schema.sql not present"
85
87
  end
86
- end
87
88
 
88
- desc "Dump the database schema"
89
- task :dump do
90
- file = File.join("db", "schema.sql")
91
- database_url = database_urls.first
92
- `pg_dump -i -s -x -O -f #{file} #{database_url}`
93
-
94
- schema = File.read(file)
95
- # filter all COMMENT ON EXTENSION, only owners and the db
96
- # superuser can execute these, making it impossible to just
97
- # replay such statements in certain production databases
98
- schema.gsub!(/^COMMENT ON EXTENSION.*\n/, "")
99
-
100
- # add migrations used to compose this schema
101
- db = Sequel.connect(database_urls.first)
102
- if db.table_exists?(:schema_migrations)
103
- db[:schema_migrations].each do |migration|
104
- schema << db[:schema_migrations].insert_sql(migration) + ";\n"
89
+ desc "Dump the database schema"
90
+ task :dump do
91
+ file = File.join("db", "schema.sql")
92
+ database_url = database_urls.first
93
+ `pg_dump -i -s -x -O -f #{file} #{database_url}`
94
+
95
+ schema = File.read(file)
96
+ # filter all COMMENT ON EXTENSION, only owners and the db
97
+ # superuser can execute these, making it impossible to just
98
+ # replay such statements in certain production databases
99
+ schema.gsub!(/^COMMENT ON EXTENSION.*\n/, "")
100
+
101
+ # add migrations used to compose this schema
102
+ db = Sequel.connect(database_urls.first)
103
+ if db.table_exists?(:schema_migrations)
104
+ db[:schema_migrations].each do |migration|
105
+ schema << db[:schema_migrations].insert_sql(migration) + ";\n"
106
+ end
105
107
  end
108
+ disconnect
109
+
110
+ File.open(file, "w") { |f| f.puts schema }
111
+ puts "Dumped `#{name_from_uri(database_url)}` to #{file}"
106
112
  end
107
- disconnect
108
113
 
109
- File.open(file, "w") { |f| f.puts schema }
110
- puts "Dumped `#{name_from_uri(database_url)}` to #{file}"
114
+ desc "Merges migrations into schema and removes them"
115
+ task :merge => ["db:setup", "db:schema:dump"] do
116
+ FileUtils.rm Dir["./db/migrate/*.rb"]
117
+ puts "Removed migrations"
118
+ end
111
119
  end
112
120
 
113
- desc "Merges migrations into schema and removes them"
114
- task :merge => ["db:setup", "db:schema:dump"] do
115
- FileUtils.rm Dir["./db/migrate/*.rb"]
116
- puts "Removed migrations"
117
- end
118
- end
121
+ desc "Setup the database"
122
+ task :setup => [:drop, :create, "schema:load", :migrate, :seed]
119
123
 
120
- desc "Setup the database"
121
- task :setup => [:drop, :create, "schema:load", :migrate, :seed]
124
+ private
122
125
 
123
- private
126
+ def disconnect
127
+ Sequel::DATABASES.each { |db| db.disconnect }
128
+ Sequel::DATABASES.clear
129
+ end
124
130
 
125
- def disconnect
126
- Sequel::DATABASES.each { |db| db.disconnect }
127
- Sequel::DATABASES.clear
128
- end
131
+ def database_urls
132
+ if ENV["DATABASE_URL"]
133
+ [ENV["DATABASE_URL"]]
134
+ else
135
+ %w(.env .env.test).map { |env_file|
136
+ env_path = "./#{env_file}"
137
+ if File.exists?(env_path)
138
+ Pliny::Utils.parse_env(env_path)["DATABASE_URL"]
139
+ else
140
+ nil
141
+ end
142
+ }.compact
143
+ end
144
+ end
129
145
 
130
- def database_urls
131
- if ENV["DATABASE_URL"]
132
- [ENV["DATABASE_URL"]]
133
- else
134
- %w(.env .env.test).map { |env_file|
135
- env_path = "./#{env_file}"
136
- if File.exists?(env_path)
137
- Pliny::Utils.parse_env(env_path)["DATABASE_URL"]
138
- else
139
- nil
140
- end
141
- }.compact
146
+ def name_from_uri(uri)
147
+ URI.parse(uri).path[1..-1]
142
148
  end
143
149
  end
144
150
 
145
- def name_from_uri(uri)
146
- URI.parse(uri).path[1..-1]
147
- end
151
+ rescue LoadError
152
+ puts "Couldn't load sequel. Skipping database tasks"
148
153
  end
data/lib/pliny/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -10,7 +10,6 @@ describe Pliny::Commands::Generator::Base do
10
10
  describe '#name' do
11
11
  it 'generates a normalized name given differents argument formats' do
12
12
  [
13
- %w(resource history),
14
13
  'resource history',
15
14
  'resource-history',
16
15
  'resource_history',
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.11.0
4
+ version: 0.11.1
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-08-05 00:00:00.000000000 Z
12
+ date: 2015-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport