ridgepole-rails 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0d4170bb02ec6accce0f3b2a8216e1d401cf028
4
+ data.tar.gz: b4a9a5a253a4c2c9ea7d0e27798b36abacf1c368
5
+ SHA512:
6
+ metadata.gz: 89793f2430324b0b0b36dce3a5d6594dace4e2e982a0e7d6ead2786888839aca3a5c4749efa157f9acea98e755aa80d7cff9d13c5bc8092cf7808eeca853ea46
7
+ data.tar.gz: 9a4abdfd7c0e630cea913d407b547e557f70be18ec395ff17d3c2ca8f9e2f66844e15ce977660b8e2684e26b97f59a6f23a14e69b8b427f2fc991d21fa550f30
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 OZAWA Sakuro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Ridgepole-rails
2
+
3
+ Ridgepole-rails provides two Rake tasks: `ridgepole:export` and `ridgepole:apply`
4
+ They wrap [ridgepole](https://github.com/winebarrel/ridgepole)'s `ridgepole --export` and
5
+ `ridgepole --apply` respectively.
6
+
7
+ ## Usage
8
+
9
+ To export current schema of the database to Schemafile
10
+
11
+ rake ridgepole:export
12
+
13
+ To apply Schemafile to the database
14
+
15
+ rake ridgepole:apply
16
+
17
+ Some db tasks of Rails are replaced as follows:
18
+
19
+ * `db:migrate` invokes `ridgepole:apply` then `ridgepole:export`
20
+ * `db:schema:dump` invokes `ridgepole:export`
21
+ * `db:schema:load` invokes `ridgepole:apply`
22
+ * `db:test:load` invokes `ridgepole:apply` with first argument: `test`
23
+ * `db:migrate:status`, `db:rollback` and `db:version` are undefined
24
+
25
+ TODO: Some means not to replace these tasks above.
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+ ```ruby
31
+ gem 'ridgepole-rails'
32
+ ```
33
+
34
+ And then execute:
35
+ ```bash
36
+ $ bundle
37
+ ```
38
+
39
+ Or install it yourself as:
40
+ ```bash
41
+ $ gem install ridgepole-rails
42
+ ```
43
+
44
+ ## Contributing
45
+ Contribution directions go here.
46
+
47
+ ## License
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'bundler/gem_tasks'
@@ -0,0 +1 @@
1
+ require 'ridgepole/rails/engine'
@@ -0,0 +1,6 @@
1
+ module Ridgepole
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,58 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'shellwords'
4
+
5
+ module Ridgepole
6
+ module Rails
7
+ class RakeTask < ::Rake::TaskLib
8
+ def initialize(name)
9
+ task name, :rails_env do |_t, args|
10
+ self.operation = name
11
+ yield self if block_given?
12
+ options = {out: IO::NULL}
13
+ sh Command.build(operation, args[:rails_env]).command, options
14
+ end
15
+ end
16
+
17
+ attr_accessor :operation
18
+ end
19
+
20
+ class Command
21
+ RIDGEPOLE_COMMAND = 'bundle exec ridgepole'.shellsplit
22
+
23
+ class << self
24
+ def build(operation, env)
25
+ const_get(operation.classify).new(env)
26
+ end
27
+ end
28
+
29
+ def initialize(env)
30
+ @env = env || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
31
+ end
32
+
33
+ private
34
+
35
+ def ignore_tables
36
+ ActiveRecord::SchemaDumper.ignore_tables.map(&:source)
37
+ end
38
+
39
+ def options
40
+ options_hash = { '-E' => @env, '-c' => 'config/database.yml' }
41
+ options_hash['--ignore-tables'] = ignore_tables.join(',') if ignore_tables.size > 0
42
+ options_hash.to_a.flatten
43
+ end
44
+
45
+ class Export < self
46
+ def command
47
+ [*RIDGEPOLE_COMMAND, *%w(--export -o Schemafile), *options].shelljoin
48
+ end
49
+ end
50
+
51
+ class Apply < self
52
+ def command
53
+ [*RIDGEPOLE_COMMAND, *%w(--apply), *options].shelljoin
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Ridgepole
2
+ module Rails
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'ridgepole/rails/rake_task'
2
+
3
+ namespace :ridgepole do
4
+ desc 'Export the database schema to Schemafile'
5
+ Ridgepole::Rails::RakeTask.new('export')
6
+
7
+ desc 'Apply Schemafile to the database'
8
+ Ridgepole::Rails::RakeTask.new('apply')
9
+ end
10
+
11
+ Rake.application.lookup('db:migrate').clear
12
+ desc 'Migrate the database by Ridgepole'
13
+ task 'db:migrate' => %w(ridgepole:apply ridgepole:export)
14
+
15
+ Rake.application.lookup('db:schema:dump').clear
16
+ desc 'Export the database schema to Schemafile'
17
+ task 'db:schema:dump' => 'ridgepole:export'
18
+
19
+ Rake.application.lookup('db:schema:load').clear
20
+ desc 'Apply Schemafile to the database'
21
+ task 'db:schema:load' => 'ridgepole:apply'
22
+
23
+ Rake.application.lookup('db:test:load').clear
24
+ task 'db:test:load' => %w(db:test:purge) do
25
+ Rake::Task['ridgepole:apply'].invoke('test')
26
+ end
27
+
28
+ %w(db:migrate:status db:rollback db:version).each do |name|
29
+ Rake.application.lookup(name).clear
30
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ridgepole-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - OZAWA Sakuro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: ridgepole
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.5.beta9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.5.beta9
41
+ description: |
42
+ This gem adds two rake tasks: ridgepole:export and ridgepole:apply to your rails project.
43
+ It also substitutes some builtin tasks (db:migrate db:schema:dump etc.)
44
+ email:
45
+ - sakuro@2238club.org
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - MIT-LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/ridgepole/rails.rb
54
+ - lib/ridgepole/rails/engine.rb
55
+ - lib/ridgepole/rails/rake_task.rb
56
+ - lib/ridgepole/rails/version.rb
57
+ - lib/tasks/ridgepole.rake
58
+ homepage: https://github.com/sakuro/ridgepole-rails
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.11
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Integrates ridgepole into rails
82
+ test_files: []