pliny 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +1 -2
  3. data/lib/pliny/commands/creator.rb +3 -3
  4. data/lib/pliny/commands/generator/base.rb +6 -2
  5. data/lib/pliny/commands/generator/endpoint.rb +3 -3
  6. data/lib/pliny/commands/generator/mediator.rb +2 -2
  7. data/lib/pliny/commands/generator/migration.rb +1 -1
  8. data/lib/pliny/commands/generator/model.rb +3 -3
  9. data/lib/pliny/commands/generator/serializer.rb +2 -2
  10. data/lib/pliny/config_helpers.rb +1 -1
  11. data/lib/pliny/tasks/db.rake +23 -4
  12. data/lib/pliny/templates/endpoint.erb +4 -4
  13. data/lib/pliny/templates/endpoint_acceptance_test.erb +5 -5
  14. data/lib/pliny/templates/endpoint_test.erb +1 -1
  15. data/lib/pliny/version.rb +1 -1
  16. data/{template → lib/template}/.env.sample +0 -0
  17. data/{template → lib/template}/.env.test +0 -0
  18. data/{template → lib/template}/.gitignore +0 -0
  19. data/{template → lib/template}/.rspec +0 -0
  20. data/lib/template/.ruby-version +1 -0
  21. data/{template → lib/template}/Gemfile +7 -10
  22. data/{template → lib/template}/LICENSE +0 -0
  23. data/{template → lib/template}/Procfile +0 -0
  24. data/{template → lib/template}/README.md +0 -0
  25. data/lib/template/Rakefile +6 -0
  26. data/{template → lib/template}/bin/console +2 -10
  27. data/{template → lib/template}/bin/run +0 -0
  28. data/{template → lib/template}/bin/setup +1 -1
  29. data/{template → lib/template}/config.ru +0 -0
  30. data/{template → lib/template}/config/config.rb +1 -1
  31. data/{template → lib/template}/config/initializers/database.rb +0 -0
  32. data/{template → lib/template}/config/initializers/rollbar.rb +0 -0
  33. data/{template → lib/template}/config/puma.rb +0 -0
  34. data/{template → lib/template}/db/schema.sql +0 -0
  35. data/{template → lib/template}/db/seeds.rb +0 -0
  36. data/{template → lib/template}/docs/schema/meta.json +0 -0
  37. data/{template → lib/template}/docs/schema/schemata/.gitkeep +0 -0
  38. data/{template → lib/template}/lib/application.rb +0 -0
  39. data/{template → lib/template}/lib/endpoints/base.rb +0 -0
  40. data/{template → lib/template}/lib/endpoints/root.rb +0 -0
  41. data/{template → lib/template}/lib/initializer.rb +0 -0
  42. data/{template → lib/template}/lib/mediators/base.rb +0 -0
  43. data/{template → lib/template}/lib/routes.rb +0 -0
  44. data/{template → lib/template}/lib/serializers/base.rb +0 -0
  45. data/lib/template/lib/tasks/spec.rake +10 -0
  46. data/{template → lib/template}/spec/spec_helper.rb +1 -0
  47. data/{template → lib/template}/spec/support/auto_define_rack_app.rb +0 -0
  48. data/{template → lib/template}/spec/support/log.rb +0 -0
  49. data/spec/commands/generator/endpoint_spec.rb +44 -2
  50. data/spec/integration_spec.rb +17 -7
  51. data/spec/spec_helper.rb +14 -1
  52. data/spec/support/config.rb +8 -0
  53. data/spec/support/endpoints.rb +8 -0
  54. metadata +134 -97
  55. data/template/.ruby-version +0 -1
  56. data/template/Gemfile.lock +0 -138
  57. data/template/Rakefile +0 -14
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NmVlMTRhYThlZWVjYzA2MjNlYjZjZDY5NTkyMDY5YmE5NWEwNDAyMA==
5
- data.tar.gz: !binary |-
6
- MTczNDRhNTY2N2UwMmUyY2I4YWQ5NDFlN2MwYzhlN2JlNTVhOWIwYw==
2
+ SHA1:
3
+ metadata.gz: 062483bed93d424e25354d0f8ea06a181a28430c
4
+ data.tar.gz: b1c03ea6b109d2f66bd858f35b9ed1b1662a8ade
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MTM1OTZkNmMxMDcwMTg4ZWVkYWFkN2MxMjQ3MWM5MzdhNmE4M2NkZmYxMjA4
10
- YzM5MGRmZmFlM2YyMzJmMTE3YzM3ZGVmMjYxNTk3YWRjOTdhODA4YTcwY2Ew
11
- OWQyNjQ3YTlhZmZmYTBjN2UxMjFlMDEwZGRlMTA5NTI0OTJhYmM=
12
- data.tar.gz: !binary |-
13
- OGY5YmExZmE5YTQwMGQ4MWNiNzkyYTMwZDA1NjNmZTI5YmM1ZWY4YTFjYTQx
14
- ZDIwZDkxZDdjNmY1ZjlkZDQ2Y2EyM2NlZTNhY2NmNjQ1N2M1MzY4MTViN2Q0
15
- ZmIxZmY1MTQ0MjIyNmNiOGE2OTQwZTk3YzJkOTBiMzQwNWM5Mjk=
6
+ metadata.gz: 1f22ef6e9a03877ea2b9e41451579c708fc54553e2b6cc979262859bccc204a2f9e10ea43111aacb3bd033945a315337996288abd7b419f4c835952181e7c406
7
+ data.tar.gz: 94fac3320131a3cc7fe13bdb52752dcedc6aadd17e832ef4e21f37c7a68d9df1ace62277c28685ac1c073ae422faa01ba2a0ea1172ba9804d8b571d170736ff5
data/README.md CHANGED
@@ -19,7 +19,7 @@ And gems/helpers to tie these together and support operations:
19
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
20
  - [Mediators](http://brandur.org/mediator) to help encapsulate more complex interactions
21
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](https://github.com/interagent/pliny-template/blob/master/config/puma.rb)
22
+ - [Puma](http://puma.io/) as the web server, [configured for optimal performance on Heroku](lib/template/config/puma.rb)
23
23
  - [Rack-test](https://github.com/brynary/rack-test) to test the API endpoints
24
24
  - [Request IDs](lib/pliny/middleware/request_id.rb)
25
25
  - [RequestStore](http://brandur.org/antipatterns), thread safe option to store data with the current request
@@ -141,7 +141,6 @@ Run tests:
141
141
 
142
142
  ```
143
143
  $ bundle install
144
- $ git submodule update --init
145
144
  $ rake
146
145
  ```
147
146
 
@@ -1,5 +1,5 @@
1
- require 'pliny/version'
2
1
  require 'fileutils'
2
+ require 'pathname'
3
3
  require 'uri'
4
4
 
5
5
  module Pliny::Commands
@@ -55,11 +55,11 @@ module Pliny::Commands
55
55
  end
56
56
 
57
57
  def template_dir
58
- File.expand_path('../../../template', File.dirname(__FILE__))
58
+ File.expand_path('../../template', File.dirname(__FILE__))
59
59
  end
60
60
 
61
61
  def app_dir
62
- "./#{name}"
62
+ Pathname.new(name).expand_path
63
63
  end
64
64
  end
65
65
  end
@@ -39,12 +39,16 @@ module Pliny::Commands
39
39
  stream.puts msg
40
40
  end
41
41
 
42
- def render_template(template_file, destination_path, vars = {})
42
+ def render_template(template_file, vars = {})
43
43
  template_path = File.dirname(__FILE__) + "/../../templates/#{template_file}"
44
44
  template = ERB.new(File.read(template_path), 0, '>')
45
45
  context = OpenStruct.new(vars)
46
+ template.result(context.instance_eval { binding })
47
+ end
48
+
49
+ def write_template(template_file, destination_path, vars = {})
46
50
  write_file(destination_path) do
47
- template.result(context.instance_eval { binding })
51
+ render_template(template_file, vars)
48
52
  end
49
53
  end
50
54
 
@@ -6,7 +6,7 @@ module Pliny::Commands
6
6
  def create
7
7
  endpoint = "./lib/endpoints/#{pluralized_file_name}.rb"
8
8
  template = options[:scaffold] ? 'endpoint_scaffold.erb' : 'endpoint.erb'
9
- render_template(template, endpoint,
9
+ write_template(template, endpoint,
10
10
  plural_class_name: plural_class_name,
11
11
  singular_class_name: singular_class_name,
12
12
  field_name: field_name,
@@ -18,7 +18,7 @@ module Pliny::Commands
18
18
 
19
19
  def create_test
20
20
  test = "./spec/endpoints/#{pluralized_file_name}_spec.rb"
21
- render_template('endpoint_test.erb', test,
21
+ write_template('endpoint_test.erb', test,
22
22
  plural_class_name: plural_class_name,
23
23
  singular_class_name: singular_class_name,
24
24
  url_path: url_path)
@@ -28,7 +28,7 @@ module Pliny::Commands
28
28
  def create_acceptance_test
29
29
  test = "./spec/acceptance/#{pluralized_file_name}_spec.rb"
30
30
  template = options[:scaffold] ? 'endpoint_scaffold_acceptance_test.erb' : 'endpoint_acceptance_test.erb'
31
- render_template(template, test,
31
+ write_template(template, test,
32
32
  plural_class_name: plural_class_name,
33
33
  field_name: field_name,
34
34
  singular_class_name: singular_class_name,
@@ -5,14 +5,14 @@ module Pliny::Commands
5
5
  class Mediator < Base
6
6
  def create
7
7
  mediator = "./lib/mediators/#{field_name}.rb"
8
- render_template('mediator.erb', mediator,
8
+ write_template('mediator.erb', mediator,
9
9
  singular_class_name: singular_class_name)
10
10
  display "created mediator file #{mediator}"
11
11
  end
12
12
 
13
13
  def create_test
14
14
  test = "./spec/mediators/#{field_name}_spec.rb"
15
- render_template('mediator_test.erb', test,
15
+ write_template('mediator_test.erb', test,
16
16
  singular_class_name: singular_class_name)
17
17
  display "created test #{test}"
18
18
  end
@@ -5,7 +5,7 @@ module Pliny::Commands
5
5
  class Migration < Base
6
6
  def create
7
7
  migration = "./db/migrate/#{Time.now.to_i}_#{name}.rb"
8
- render_template('migration.erb', migration)
8
+ write_template('migration.erb', migration)
9
9
  display "created migration #{migration}"
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module Pliny::Commands
5
5
  class Model < Base
6
6
  def create
7
7
  model = "./lib/models/#{field_name}.rb"
8
- render_template('model.erb', model,
8
+ write_template('model.erb', model,
9
9
  singular_class_name: singular_class_name,
10
10
  paranoid: options[:paranoid])
11
11
  display "created model file #{model}"
@@ -13,7 +13,7 @@ module Pliny::Commands
13
13
 
14
14
  def create_migration
15
15
  migration = "./db/migrate/#{Time.now.to_i}_create_#{table_name}.rb"
16
- render_template('model_migration.erb', migration,
16
+ write_template('model_migration.erb', migration,
17
17
  table_name: table_name,
18
18
  paranoid: options[:paranoid])
19
19
  display "created migration #{migration}"
@@ -21,7 +21,7 @@ module Pliny::Commands
21
21
 
22
22
  def create_test
23
23
  test = "./spec/models/#{field_name}_spec.rb"
24
- render_template('model_test.erb', test,
24
+ write_template('model_test.erb', test,
25
25
  singular_class_name: singular_class_name)
26
26
  display "created test #{test}"
27
27
  end
@@ -5,14 +5,14 @@ module Pliny::Commands
5
5
  class Serializer < Base
6
6
  def create
7
7
  serializer = "./lib/serializers/#{field_name}.rb"
8
- render_template('serializer.erb', serializer,
8
+ write_template('serializer.erb', serializer,
9
9
  singular_class_name: singular_class_name)
10
10
  display "created serializer file #{serializer}"
11
11
  end
12
12
 
13
13
  def create_test
14
14
  test = "./spec/serializers/#{field_name}_spec.rb"
15
- render_template('serializer_test.erb', test,
15
+ write_template('serializer_test.erb', test,
16
16
  singular_class_name: singular_class_name)
17
17
  display "created test #{test}"
18
18
  end
@@ -83,4 +83,4 @@ module Pliny
83
83
  end
84
84
 
85
85
  # Supress the "use RbConfig instead" warning.
86
- Object.send :remove_const, :Config
86
+ Object.send(:remove_const, :Config) if Object.const_defined?(:Config)
@@ -13,6 +13,7 @@ namespace :db do
13
13
  Sequel::Migrator.apply(db, "./db/migrate")
14
14
  puts "Migrated `#{name_from_uri(database_url)}`"
15
15
  end
16
+ disconnect
16
17
  end
17
18
 
18
19
  desc "Rollback the database"
@@ -23,6 +24,7 @@ namespace :db do
23
24
  Sequel::Migrator.apply(db, "./db/migrate", -1)
24
25
  puts "Rolled back `#{name_from_uri(database_url)}`"
25
26
  end
27
+ disconnect
26
28
  end
27
29
 
28
30
  desc "Nuke the database (drop all tables)"
@@ -34,6 +36,7 @@ namespace :db do
34
36
  end
35
37
  puts "Nuked `#{name_from_uri(database_url)}`"
36
38
  end
39
+ disconnect
37
40
  end
38
41
 
39
42
  desc "Seed the database with data"
@@ -43,6 +46,7 @@ namespace :db do
43
46
  Sequel.connect(database_url)
44
47
  load 'db/seeds.rb'
45
48
  end
49
+ disconnect
46
50
  end
47
51
  end
48
52
 
@@ -51,8 +55,8 @@ namespace :db do
51
55
 
52
56
  desc "Create the database"
53
57
  task :create do
54
- db = Sequel.connect("postgres:///postgres")
55
58
  database_urls.each do |database_url|
59
+ db = Sequel.connect("#{postgres_location_from_uri(database_url)}/postgres")
56
60
  exists = false
57
61
  name = name_from_uri(database_url)
58
62
  begin
@@ -63,16 +67,18 @@ namespace :db do
63
67
  end
64
68
  puts "Created `#{name}`" if !exists
65
69
  end
70
+ disconnect
66
71
  end
67
72
 
68
73
  desc "Drop the database"
69
74
  task :drop do
70
- db = Sequel.connect("postgres:///postgres")
71
75
  database_urls.each do |database_url|
76
+ db = Sequel.connect("#{postgres_location_from_uri(database_url)}/postgres")
72
77
  name = name_from_uri(database_url)
73
78
  db.run(%{DROP DATABASE IF EXISTS "#{name}"})
74
79
  puts "Dropped `#{name}`"
75
80
  end
81
+ disconnect
76
82
  end
77
83
 
78
84
  namespace :schema do
@@ -85,6 +91,7 @@ namespace :db do
85
91
  db.run(schema)
86
92
  puts "Loaded `#{name_from_uri(database_url)}`"
87
93
  end
94
+ disconnect
88
95
  else
89
96
  puts "Skipped schema load, schema.sql not present"
90
97
  end
@@ -109,23 +116,29 @@ namespace :db do
109
116
  schema << db[:schema_migrations].insert_sql(migration) + ";\n"
110
117
  end
111
118
  end
119
+ disconnect
112
120
 
113
121
  File.open(file, "w") { |f| f.puts schema }
114
122
  puts "Dumped `#{name_from_uri(database_url)}` to #{file}"
115
123
  end
116
124
 
117
125
  desc "Merges migrations into schema and removes them"
118
- task :merge => ["db:setup", "db:schema:load", "db:migrate", "db:schema:dump"] do
126
+ task :merge => ["db:setup", "db:schema:dump"] do
119
127
  FileUtils.rm Dir["./db/migrate/*.rb"]
120
128
  puts "Removed migrations"
121
129
  end
122
130
  end
123
131
 
124
132
  desc "Setup the database"
125
- task :setup => [:drop, :create, :migrate]
133
+ task :setup => [:drop, :create, "schema:load", :migrate]
126
134
 
127
135
  private
128
136
 
137
+ def disconnect
138
+ Sequel::DATABASES.each { |db| db.disconnect }
139
+ Sequel::DATABASES.clear
140
+ end
141
+
129
142
  def database_urls
130
143
  if ENV["DATABASE_URL"]
131
144
  [ENV["DATABASE_URL"]]
@@ -144,4 +157,10 @@ namespace :db do
144
157
  def name_from_uri(uri)
145
158
  URI.parse(uri).path[1..-1]
146
159
  end
160
+
161
+ def postgres_location_from_uri(uri)
162
+ p = URI.parse(uri)
163
+ p.path = ""
164
+ p.to_s
165
+ end
147
166
  end
@@ -11,19 +11,19 @@ module Endpoints
11
11
 
12
12
  post do
13
13
  status 201
14
- encode {}
14
+ encode Hash.new
15
15
  end
16
16
 
17
17
  get "/:id" do
18
- encode {}
18
+ encode Hash.new
19
19
  end
20
20
 
21
21
  patch "/:id" do |id|
22
- encode {}
22
+ encode Hash.new
23
23
  end
24
24
 
25
25
  delete "/:id" do |id|
26
- encode {}
26
+ encode Hash.new
27
27
  end
28
28
  end
29
29
  end
@@ -15,7 +15,7 @@ describe Endpoints::<%= plural_class_name %> do
15
15
  describe 'GET <%= url_path %>' do
16
16
  it 'returns correct status code and conforms to schema' do
17
17
  get '<%= url_path %>'
18
- expect(last_response.status).to eq(200)
18
+ assert_equal 200, last_response.status
19
19
  assert_schema_conform
20
20
  end
21
21
  end
@@ -24,7 +24,7 @@ describe Endpoints::<%= plural_class_name %> 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({})
27
- expect(last_response.status).to eq(201)
27
+ assert_equal 201, last_response.status
28
28
  assert_schema_conform
29
29
  end
30
30
  end
@@ -32,7 +32,7 @@ describe Endpoints::<%= plural_class_name %> do
32
32
  describe 'GET <%= url_path %>/:id' do
33
33
  it 'returns correct status code and conforms to schema' do
34
34
  get "<%= url_path %>/123"
35
- expect(last_response.status).to eq(200)
35
+ assert_equal 200, last_response.status
36
36
  assert_schema_conform
37
37
  end
38
38
  end
@@ -41,7 +41,7 @@ describe Endpoints::<%= plural_class_name %> do
41
41
  it 'returns correct status code and conforms to schema' do
42
42
  header "Content-Type", "application/json"
43
43
  patch '<%= url_path %>/123', MultiJson.encode({})
44
- expect(last_response.status).to eq(200)
44
+ assert_equal 200, last_response.status
45
45
  assert_schema_conform
46
46
  end
47
47
  end
@@ -49,7 +49,7 @@ describe Endpoints::<%= plural_class_name %> do
49
49
  describe 'DELETE <%= url_path %>/:id' do
50
50
  it 'returns correct status code and conforms to schema' do
51
51
  delete '<%= url_path %>/123'
52
- expect(last_response.status).to eq(200)
52
+ assert_equal 200, last_response.status
53
53
  assert_schema_conform
54
54
  end
55
55
  end
@@ -6,7 +6,7 @@ describe Endpoints::<%= plural_class_name %> do
6
6
  describe "GET <%= url_path %>" do
7
7
  it "succeeds" do
8
8
  get "<%= url_path %>"
9
- expect(last_response.status).to eq(200)
9
+ assert_equal 200, last_response.status
10
10
  end
11
11
  end
12
12
  end
data/lib/pliny/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ 2.2.0
@@ -1,20 +1,20 @@
1
1
  source "https://rubygems.org"
2
- ruby "2.1.4"
2
+ ruby "2.2.0"
3
3
 
4
4
  gem "multi_json"
5
5
  gem "oj"
6
6
  gem "pg"
7
- gem "pliny"
7
+ gem "pliny", "~> 0.5"
8
8
  gem "pry"
9
9
  gem "pry-doc"
10
- gem "puma"
10
+ gem "puma", "~> 2.10"
11
11
  gem "rack-ssl"
12
12
  gem "rake"
13
13
  gem "rollbar"
14
- gem "sequel"
14
+ gem "sequel", "~> 4.16"
15
15
  gem "sequel-paranoid"
16
- gem "sequel_pg", require: "sequel"
17
- gem "sinatra", require: "sinatra/base"
16
+ gem "sequel_pg", "~> 1.6", require: "sequel"
17
+ gem "sinatra", "~> 1.4", require: "sinatra/base"
18
18
  gem "sinatra-contrib", require: ["sinatra/namespace", "sinatra/reloader"]
19
19
  gem "sinatra-router"
20
20
  gem "sucker_punch"
@@ -23,13 +23,10 @@ group :development, :test do
23
23
  gem "pry-byebug"
24
24
  end
25
25
 
26
- group :development do
27
- gem "dotenv"
28
- end
29
-
30
26
  group :test do
31
27
  gem "committee"
32
28
  gem "database_cleaner"
29
+ gem "dotenv"
33
30
  gem "rack-test"
34
31
  gem "rspec"
35
32
  end
File without changes
File without changes
File without changes