extort 0.2.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 064ce5fe8c21d7eaf004c332d18e83e5959e9734
4
+ data.tar.gz: 2ea2c254ea410eb18555d7ddd4b303cbaa0fe471
5
+ SHA512:
6
+ metadata.gz: abc7b5964a6603a471d410f90c68e4a43340935bc798848f926657ea5f9ac163f34382f09c74d18693fc9e651deff90817f9f654f2267d7bf9e7bdb2df14d3e6
7
+ data.tar.gz: f5ef110a4dd8bbc36fe94347f14f363505b7ff1e52440021a136f43c5025917479ea1b4e39dfa935e8f240f019570dcc08ebba60fa733f522837023ae18c0b20
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /test/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in extort.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 dknl
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Extort
2
+
3
+ A simple helper for handling Sequel migrations in Sinatra app.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'extort'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install extort
20
+
21
+ ## Usage
22
+
23
+ Extort expects $DB exists. This way all migrations can be executed onto this connection.
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/amaniak/extort/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/extort.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'extort/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "extort"
8
+ spec.version = Extort::VERSION
9
+ spec.authors = ["DK"]
10
+ spec.email = ["dk@nutshell.nl"]
11
+ spec.summary = %q{Extort adds migrations to common apps}
12
+ spec.description = %q{Extort sets up Sequel migrations for Sinatra apps}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "pry", "~> 0.10.1"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency "sequel", "~> 4.21.0"
25
+ end
@@ -0,0 +1,3 @@
1
+ module Extort
2
+ VERSION = "0.2.1"
3
+ end
data/lib/extort.rb ADDED
@@ -0,0 +1,150 @@
1
+ require 'fileutils'
2
+ require 'sequel'
3
+
4
+ require "extort/version"
5
+
6
+ # Add migration extension to Sequel
7
+ Sequel.extension :migration
8
+
9
+
10
+ # Extort
11
+ module Extort
12
+
13
+ class << self
14
+
15
+ # Includes
16
+
17
+ include Rake::DSL if defined? Rake::DSL
18
+
19
+ # Constants
20
+
21
+ NO_VERSION_FOUND = "no version found"
22
+ DB_MIGRATIONS_DIR = "db"
23
+
24
+ # Get current working directiry
25
+ # @return [String] current directory
26
+
27
+ def pwd
28
+ Dir.pwd
29
+ end
30
+
31
+ # Check for schema table
32
+ # @return [Boolean]
33
+
34
+ def schema_table?
35
+ $DB.tables.include?(:schema_migrations)
36
+ end
37
+
38
+ # Get schema version
39
+ # @return [String] version of schema
40
+
41
+ def schema_version
42
+ if schema_table?
43
+ version_from_field \
44
+ $DB[:schema_migrations].order(:filename).last
45
+ else
46
+ NO_VERSION_FOUND
47
+ end
48
+ end
49
+
50
+ # Print all versions
51
+ # @return [Array] with versions
52
+
53
+ def schema_versions
54
+ $DB[:schema_migrations].map do |record|
55
+ version_from_field(record)
56
+ end
57
+ end
58
+
59
+ # Version from database column
60
+ # @param record [Hash] raw database record
61
+ # @return [String] timestamp
62
+
63
+ def version_from_field record
64
+ unless record.nil?
65
+ record[:filename].split("_").first
66
+ end
67
+ end
68
+
69
+ # Execute pending migrations
70
+ # @return [Void]
71
+
72
+ def migrate
73
+ Sequel::Migrator.run $DB, File.join(pwd, DB_MIGRATIONS_DIR)
74
+ end
75
+
76
+ # Rollback migration
77
+ # @return [Void]
78
+
79
+ def rollback step
80
+ argument_error(step)
81
+ Sequel::Migrator.run $DB, File.join(pwd, DB_MIGRATIONS_DIR), \
82
+ target: step.to_i
83
+ end
84
+
85
+ # Add a new migration file
86
+ # @return [String] file path
87
+
88
+ def add_migration name
89
+ argument_error(name)
90
+ FileUtils.touch filename(name)
91
+ end
92
+
93
+
94
+ # Setup new extort env.
95
+ # @return [Boolean]
96
+
97
+ def init
98
+ if Dir.exists?(DB_MIGRATIONS_DIR)
99
+ "#{DB_MIGRATIONS_DIR} directory already exists"
100
+ else
101
+ FileUtils.mkdir_p(DB_MIGRATIONS_DIR)
102
+ "#{DB_MIGRATIONS_DIR} directory created"
103
+ end
104
+ end
105
+
106
+
107
+ # Return directory of gem.
108
+ # @return [String] path to gem directory
109
+
110
+ def spec_directory
111
+ @spec_directory ||= \
112
+
113
+ Gem::Specification
114
+ .find_by_name(self.to_s.downcase)
115
+ .gem_dir
116
+ end
117
+
118
+
119
+ # Install rake tasks (from other gems or apps)
120
+
121
+ def install_tasks
122
+
123
+ # import tasks
124
+ import "#{spec_directory}/lib/tasks/database.rake"
125
+ end
126
+
127
+ private
128
+
129
+ # Filename based on timestap an name given
130
+ #
131
+ # @param name [String] name of file
132
+ # @return [String] Path to migration file
133
+
134
+ def filename name
135
+ timestamp = Time.now.to_i.to_s << "_"
136
+ File.join(DB_MIGRATIONS_DIR, timestamp + name.downcase + '.rb')
137
+ end
138
+
139
+
140
+ # Raise argument error
141
+ #
142
+ # @param key [Symbol] argument missing
143
+
144
+ def argument_error argument
145
+ raise ArgumentError.new "Missing #{argument}" if argument.nil?
146
+ end
147
+
148
+ end
149
+
150
+ end
@@ -0,0 +1,55 @@
1
+
2
+ namespace :db do
3
+
4
+ # Actions
5
+
6
+ desc "Print all versions"
7
+ task :versions do
8
+ puts Extort.schema_versions
9
+ end
10
+
11
+ desc "Print current schema version"
12
+ task :version do
13
+ puts Extort.schema_version
14
+ end
15
+
16
+ desc "Execute database migrations"
17
+ task :migrate do
18
+ begin
19
+ Extort.migrate
20
+ Rake::Task['db:version'].execute
21
+ rescue ArgumentError => e
22
+ puts e
23
+ end
24
+ end
25
+
26
+ desc "Rollback database migrations"
27
+ task :rollback, [:step] do |t, args|
28
+ args.with_defaults(step: Extort.schema_version)
29
+ begin
30
+ Extort.rollback args[:step]
31
+ Rake::Task['db:version'].execute
32
+ rescue ArgumentError => e
33
+ puts e
34
+ end
35
+ end
36
+
37
+ desc "Init Extort for first time"
38
+ task :init do
39
+ puts Extort.init
40
+ end
41
+
42
+ # Migration namespace
43
+
44
+ namespace :migration do
45
+ desc "Add new migration file"
46
+ task :add, [:name] do |t, args|
47
+ begin
48
+ Extort.add_migration args[:name]
49
+ rescue ArgumentError => e
50
+ puts e
51
+ end
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,11 @@
1
+ Sequel.migration do
2
+
3
+ # Uppers
4
+ up do
5
+ end
6
+
7
+ # Downers
8
+ down do
9
+ end
10
+
11
+ end
data/test/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'pg'
4
+ gem 'pry'
5
+ gem 'extort', path: '../'
data/test/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ extort (0.2.1)
5
+ sequel (~> 4.21.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ coderay (1.1.0)
11
+ method_source (0.8.2)
12
+ pg (0.18.1)
13
+ pry (0.10.1)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.8.1)
16
+ slop (~> 3.4)
17
+ sequel (4.21.0)
18
+ slop (3.6.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ extort!
25
+ pg
26
+ pry
data/test/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default
5
+
6
+ require 'extort'
7
+ require 'sequel'
8
+
9
+ $DB = Sequel.connect("postgres://deploy:''@localhost/knot")
10
+
11
+ # Install extort tasks
12
+ Extort.install_tasks
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extort
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - DK
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sequel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.21.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.21.0
69
+ description: Extort sets up Sequel migrations for Sinatra apps
70
+ email:
71
+ - dk@nutshell.nl
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - extort.gemspec
82
+ - lib/extort.rb
83
+ - lib/extort/version.rb
84
+ - lib/tasks/database.rake
85
+ - lib/templates/base_migration.rb
86
+ - test/Gemfile
87
+ - test/Gemfile.lock
88
+ - test/Rakefile
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.4
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Extort adds migrations to common apps
113
+ test_files:
114
+ - test/Gemfile
115
+ - test/Gemfile.lock
116
+ - test/Rakefile
117
+ has_rdoc: