pliny 0.8.2 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05219e130e92ccf5c4feb4b920c66de370360c7b
4
- data.tar.gz: 26b7dd30a5f8a886a4ab53394422208a8a3253ab
3
+ metadata.gz: cc0fc3ea6bd2bf5b8c5b6acdcf1cabf32ea781d5
4
+ data.tar.gz: 68bcfd4977381a765954e04884680dfaefdb5b4e
5
5
  SHA512:
6
- metadata.gz: 8cd26e265b51c9aa36e6ceb2274a31d6efc5d5657c27b4687431b1dcf76b735a8faa040621af30faeeb1cd2f89076a939d6e2db792ce3079f63fa963d78a35db
7
- data.tar.gz: cd22ef6dc41f8638c0a38e861fd6ca68e18f13a7f520ee5c806493bd8bb2512fb14ec7e53bec0314dddbce5c015f37d3f6b247ab8707ddc86357a327dd3f72f0
6
+ metadata.gz: 9a7c5e06960e5076cf66d5f3951acdba7e19152d1294dbc79c6946333f701bf574b9f520d0d3fe52256a5586cf8ebdb279870785f16e6db5b66d2601d880ff0c
7
+ data.tar.gz: 67a0baee927f357155076aa8466d4358abd1b0ef6d68dec6c9db69853db8b31ef042162a50b8945cad12965411dd41b697bd495ca70bb7accb3e8dcb3ce7e4e5
data/README.md CHANGED
@@ -24,7 +24,7 @@ And gems/helpers to tie these together and support operations:
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
26
26
  - [Sequel](http://sequel.jeremyevans.net/) for ORM
27
- - [Sequel-PG](https://github.com/jeremyevans/sequel_pg) because we don't like mysql
27
+ - [Sequel-PG](https://github.com/jeremyevans/sequel_pg) to talk to the world's most advanced open source database
28
28
  - [Versioning](lib/pliny/middleware/versioning.rb) to allow versioning your API in the HTTP Accept header
29
29
 
30
30
  ## Getting started
@@ -112,8 +112,6 @@ Pliny comes with several rake tasks:
112
112
  rake db:create # Create the database
113
113
  rake db:drop # Drop the database
114
114
  rake db:migrate # Run database migrations
115
- rake db:nuke # Nuke the database (drop all tables)
116
- rake db:reset # Reset the database
117
115
  rake db:rollback # Rollback the database
118
116
  rake db:schema:dump # Dump the database schema
119
117
  rake db:schema:load # Load the database schema
@@ -135,6 +133,13 @@ $ foreman run bin/run 'puts "hello world"' # Run automated code
135
133
 
136
134
  (hint: don't forget `foreman run` in development)
137
135
 
136
+ ### Updating
137
+
138
+ Use `pliny-update` to update the Pliny app in the current directory.
139
+
140
+ This not only bumps the version dependency, but also applies any changes that happened in the template app (for instance: new initializer, tweaks in the base endpoint, etc).
141
+
142
+
138
143
  ## Development
139
144
 
140
145
  Run tests:
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require_relative '../lib/pliny/commands/updater'
5
+
6
+ Pliny::Commands::Updater.run
@@ -23,8 +23,8 @@ 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)
@@ -3,11 +3,24 @@ require_relative 'base'
3
3
  module Pliny::Commands
4
4
  class Generator
5
5
  class Migration < Base
6
+ def initialize(name, options = {}, stream = $stdout)
7
+ super
8
+ @name = normalize_name(name)
9
+ end
10
+
6
11
  def create
7
12
  migration = "./db/migrate/#{Time.now.to_i}_#{name}.rb"
8
13
  write_template('migration.erb', migration)
9
14
  display "created migration #{migration}"
10
15
  end
16
+
17
+ private
18
+
19
+ def normalize_name(name)
20
+ Array(name).map(&:underscore)
21
+ .map { |n| n.tr(' ', '_') }
22
+ .join('_')
23
+ end
11
24
  end
12
25
  end
13
26
  end
@@ -0,0 +1,86 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require 'pliny/version'
4
+ require 'uri'
5
+
6
+ module Pliny::Commands
7
+ class Updater
8
+ attr_accessor :stream
9
+
10
+ def self.run(stream = $stdout)
11
+ new(stream).run!
12
+ end
13
+
14
+ def initialize(stream = $stdout)
15
+ @stream = stream
16
+ end
17
+
18
+ def run!
19
+ unless File.exist?("Gemfile.lock")
20
+ abort("Pliny app not found - looking for Gemfile.lock")
21
+ end
22
+
23
+ version_current = get_current_version
24
+ version_target = Gem::Version.new(Pliny::VERSION)
25
+
26
+ if version_current == version_target
27
+ display "Version #{version_current} is current, nothing to update."
28
+ elsif version_current > version_target
29
+ display "pliny-update is outdated. Please update it with `gem install pliny` or similar."
30
+ else
31
+ display "Updating from #{version_current} to #{version_target}..."
32
+ ensure_repo_available
33
+ save_patch(version_current, version_target)
34
+ exec_patch
35
+ end
36
+ end
37
+
38
+ # we need a local copy of the pliny repo to produce a diff
39
+ def ensure_repo_available
40
+ if File.exists?(repo_dir)
41
+ unless system("cd #{repo_dir} && git fetch --tags")
42
+ abort("Could not update Pliny repo at #{repo_dir}")
43
+ end
44
+ else
45
+ unless system("git clone https://github.com/interagent/pliny.git #{repo_dir}")
46
+ abort("Could not git clone the Pliny repo")
47
+ end
48
+ end
49
+ end
50
+
51
+ def get_current_version
52
+ File.read("./Gemfile.lock").split("\n").each do |line|
53
+ next unless pliny_version = line.match(/pliny \(([\d+\.]+)\)/)
54
+ return Gem::Version.new(pliny_version[1])
55
+ end
56
+ end
57
+
58
+ def save_patch(curr, target)
59
+ # take a diff of changes that happened to the template app in Pliny
60
+ diff = `cd #{repo_dir} && git diff v#{curr}..v#{target} lib/template/`
61
+
62
+ # remove lib/template from the path of files in the patch so that we can
63
+ # apply these to the current folder
64
+ diff.gsub!(/^(\-\-\-|\+\+\+) (\w)\/lib\/template/, '\1 \2')
65
+
66
+ File.open(patch_file, "w") { |f| f.puts diff }
67
+ end
68
+
69
+ def exec_patch
70
+ # throw .orig and .rej files in /tmp, they're useless with source control
71
+ exec "patch --prefix=/tmp/ --reject-file=/tmp/pliny-reject -p1 < #{patch_file}"
72
+ end
73
+
74
+ def display(msg)
75
+ stream.puts msg
76
+ end
77
+
78
+ def repo_dir
79
+ File.join(Dir.home, ".tmp/pliny-repo")
80
+ end
81
+
82
+ def patch_file
83
+ File.join(repo_dir, "pliny-update.patch")
84
+ end
85
+ end
86
+ end
@@ -31,18 +31,6 @@ namespace :db do
31
31
  end
32
32
  end
33
33
 
34
- desc "Nuke the database (drop all tables)"
35
- task :nuke do
36
- database_urls.each do |database_url|
37
- db = Sequel.connect(database_url)
38
- db.tables.each do |table|
39
- db.run(%{DROP TABLE "#{table}" CASCADE})
40
- end
41
- puts "Nuked `#{name_from_uri(database_url)}`"
42
- end
43
- disconnect
44
- end
45
-
46
34
  desc "Seed the database with data"
47
35
  task :seed do
48
36
  if File.exist?('./db/seeds.rb')
@@ -54,9 +42,6 @@ namespace :db do
54
42
  end
55
43
  end
56
44
 
57
- desc "Reset the database"
58
- task :reset => [:nuke, :migrate, :seed]
59
-
60
45
  desc "Create the database"
61
46
  task :create do
62
47
  database_urls.each do |database_url|
@@ -1,5 +1,5 @@
1
1
  class <%= singular_class_name %> < Sequel::Model
2
- plugin :timestamps
2
+ plugin :timestamps, update_on_create: true
3
3
  <% if paranoid %>
4
4
  plugin :paranoid
5
5
  <% end %>
@@ -6,7 +6,7 @@ Sequel.migration do
6
6
  <% if paranoid %>
7
7
  timestamptz :deleted_at
8
8
  <% end %>
9
- timestamptz :updated_at
9
+ timestamptz :updated_at, default: Sequel.function(:now), null: false
10
10
  end
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  source "https://rubygems.org"
2
- ruby "2.2.1"
2
+ ruby "2.2.2"
3
3
 
4
4
  gem "multi_json"
5
5
  gem "oj"
6
6
  gem "pg"
7
- gem "pliny", "~> 0.8"
7
+ gem "pliny", "~> 0.9"
8
8
  gem "pry"
9
9
  gem "puma", "~> 2.10"
10
10
  gem "rack-ssl"
@@ -1 +1,2 @@
1
1
  web: bundle exec puma --config config/puma.rb config.ru
2
+ console: bundle exec bin/console
@@ -33,8 +33,7 @@ module Initializer
33
33
  end
34
34
 
35
35
  def self.require!(globs)
36
- globs = [globs] unless globs.is_a?(Array)
37
- globs.each do |f|
36
+ Array(globs).each do |f|
38
37
  Pliny::Utils.require_glob("#{Config.root}/#{f}.rb")
39
38
  end
40
39
  end
@@ -1,4 +1,4 @@
1
- class Mediators
1
+ module Mediators
2
2
  class Base
3
3
  def self.run(options={})
4
4
  new(options).call
@@ -1,8 +1,8 @@
1
1
  Routes = Rack::Builder.new do
2
2
  use Rollbar::Middleware::Sinatra
3
- use Pliny::Middleware::RescueErrors, raise: Config.raise_errors?
4
3
  use Pliny::Middleware::CORS
5
4
  use Pliny::Middleware::RequestID
5
+ use Pliny::Middleware::RescueErrors, raise: Config.raise_errors?
6
6
  use Pliny::Middleware::RequestStore, store: Pliny::RequestStore
7
7
  use Rack::Timeout if Config.timeout > 0
8
8
  use Pliny::Middleware::Versioning,
@@ -1,4 +1,4 @@
1
- class Serializers
1
+ module Serializers
2
2
  class Base
3
3
  @@structures = {}
4
4
 
@@ -0,0 +1,19 @@
1
+ require 'pliny/commands/generator'
2
+ require 'pliny/commands/generator/migration'
3
+ require 'spec_helper'
4
+
5
+ describe Pliny::Commands::Generator::Migration do
6
+ describe '#name' do
7
+ it 'generates a migration name given differents argument formats' do
8
+ [
9
+ %w(add column foo to barz),
10
+ 'add column foo to barz',
11
+ 'add_column_foo_to_barz',
12
+ 'AddColumnFooToBarz'
13
+ ].each do |argument|
14
+ actual = described_class.new(argument, {}, StringIO.new).name
15
+ assert_equal 'add_column_foo_to_barz', actual
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ require 'pliny/commands/updater'
2
+ require 'spec_helper'
3
+
4
+ describe Pliny::Commands::Updater do
5
+ before do
6
+ @io = StringIO.new
7
+ @cmd = Pliny::Commands::Updater.new(@io)
8
+
9
+ stub(@cmd).exec_patch
10
+ end
11
+
12
+ describe "#run!" do
13
+ before do
14
+ FileUtils.rm_rf("/tmp/plinytest")
15
+ FileUtils.mkdir_p("/tmp/plinytest")
16
+ Dir.chdir("/tmp/plinytest")
17
+ File.open("/tmp/plinytest/Gemfile.lock", "w") do |f|
18
+ f.puts " pliny (0.6.3)"
19
+ end
20
+ end
21
+
22
+ it "creates a patch with Pliny diffs between the two versions" do
23
+ @cmd.run!
24
+ patch = File.read(@cmd.patch_file)
25
+ assert patch.include?('--- a/Gemfile')
26
+ assert patch.include?('-gem "pliny", "~> 0.6"')
27
+ end
28
+ end
29
+ end
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.8.2
4
+ version: 0.9.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-04-29 00:00:00.000000000 Z
12
+ date: 2015-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -51,26 +51,6 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: 1.9.3
54
- - !ruby/object:Gem::Dependency
55
- name: pg
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '0.17'
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 0.17.1
64
- type: :runtime
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '0.17'
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: 0.17.1
74
54
  - !ruby/object:Gem::Dependency
75
55
  name: prmd
76
56
  requirement: !ruby/object:Gem::Requirement
@@ -105,26 +85,6 @@ dependencies:
105
85
  - - ">="
106
86
  - !ruby/object:Gem::Version
107
87
  version: 0.2.3
108
- - !ruby/object:Gem::Dependency
109
- name: sequel
110
- requirement: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - "~>"
113
- - !ruby/object:Gem::Version
114
- version: '4.9'
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: 4.9.0
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '4.9'
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- version: 4.9.0
128
88
  - !ruby/object:Gem::Dependency
129
89
  name: sinatra
130
90
  requirement: !ruby/object:Gem::Requirement
@@ -339,6 +299,46 @@ dependencies:
339
299
  - - ">="
340
300
  - !ruby/object:Gem::Version
341
301
  version: '0'
302
+ - !ruby/object:Gem::Dependency
303
+ name: pg
304
+ requirement: !ruby/object:Gem::Requirement
305
+ requirements:
306
+ - - "~>"
307
+ - !ruby/object:Gem::Version
308
+ version: '0.17'
309
+ - - ">="
310
+ - !ruby/object:Gem::Version
311
+ version: 0.17.1
312
+ type: :development
313
+ prerelease: false
314
+ version_requirements: !ruby/object:Gem::Requirement
315
+ requirements:
316
+ - - "~>"
317
+ - !ruby/object:Gem::Version
318
+ version: '0.17'
319
+ - - ">="
320
+ - !ruby/object:Gem::Version
321
+ version: 0.17.1
322
+ - !ruby/object:Gem::Dependency
323
+ name: sequel
324
+ requirement: !ruby/object:Gem::Requirement
325
+ requirements:
326
+ - - "~>"
327
+ - !ruby/object:Gem::Version
328
+ version: '4.9'
329
+ - - ">="
330
+ - !ruby/object:Gem::Version
331
+ version: 4.9.0
332
+ type: :development
333
+ prerelease: false
334
+ version_requirements: !ruby/object:Gem::Requirement
335
+ requirements:
336
+ - - "~>"
337
+ - !ruby/object:Gem::Version
338
+ version: '4.9'
339
+ - - ">="
340
+ - !ruby/object:Gem::Version
341
+ version: 4.9.0
342
342
  description: Pliny is a set of base classes and helpers to help developers write excellent
343
343
  APIs in Sinatra
344
344
  email:
@@ -347,12 +347,14 @@ email:
347
347
  executables:
348
348
  - pliny-generate
349
349
  - pliny-new
350
+ - pliny-update
350
351
  extensions: []
351
352
  extra_rdoc_files: []
352
353
  files:
353
354
  - README.md
354
355
  - bin/pliny-generate
355
356
  - bin/pliny-new
357
+ - bin/pliny-update
356
358
  - lib/pliny.rb
357
359
  - lib/pliny/commands/creator.rb
358
360
  - lib/pliny/commands/generator.rb
@@ -363,6 +365,7 @@ files:
363
365
  - lib/pliny/commands/generator/model.rb
364
366
  - lib/pliny/commands/generator/schema.rb
365
367
  - lib/pliny/commands/generator/serializer.rb
368
+ - lib/pliny/commands/updater.rb
366
369
  - lib/pliny/config_helpers.rb
367
370
  - lib/pliny/db_support.rb
368
371
  - lib/pliny/errors.rb
@@ -433,8 +436,10 @@ files:
433
436
  - spec/commands/creator_spec.rb
434
437
  - spec/commands/generator/base_spec.rb
435
438
  - spec/commands/generator/endpoint_spec.rb
439
+ - spec/commands/generator/migration_spec.rb
436
440
  - spec/commands/generator/schema_spec.rb
437
441
  - spec/commands/generator_spec.rb
442
+ - spec/commands/updater_spec.rb
438
443
  - spec/db_support_spec.rb
439
444
  - spec/errors_spec.rb
440
445
  - spec/extensions/instruments_spec.rb