schema_dev 1.4.0 → 2.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 +4 -4
- data/README.md +54 -41
- data/bin/schema_dev +14 -17
- data/lib/schema_dev/config.rb +5 -1
- data/lib/schema_dev/gem.rb +122 -0
- data/lib/schema_dev/gemfiles.rb +3 -3
- data/lib/schema_dev/readme.rb +46 -0
- data/lib/schema_dev/rspec.rb +7 -1
- data/lib/schema_dev/runner.rb +20 -8
- data/lib/schema_dev/templates.rb +9 -0
- data/lib/schema_dev/version.rb +1 -1
- data/lib/schema_dev.rb +0 -4
- data/schema_dev.gemspec +2 -0
- data/spec/gem_spec.rb +52 -0
- data/spec/gemfiles_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/templates/gem/.gitignore +8 -0
- data/templates/gem/GEM_NAME.gemspec +30 -0
- data/templates/gem/Gemfile +3 -0
- data/templates/gem/LICENSE.txt +22 -0
- data/templates/gem/README.md +62 -0
- data/templates/gem/Rakefile +9 -0
- data/templates/gem/lib/GEM_NAME/version.rb +3 -0
- data/templates/gem/lib/GEM_NAME.rb +39 -0
- data/templates/gem/schema_dev.yml +9 -0
- data/templates/gem/spec/sanity_spec.rb +13 -0
- data/templates/gem/spec/spec_helper.rb +22 -0
- data/templates/gemfiles/Gemfile.base +2 -0
- metadata +46 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1ea08cf350172c2ab73709dd71a577f961aae09
|
4
|
+
data.tar.gz: f96afa1f7bbe6224735327391fe49bb9e21cb9a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f9f21f9becb8ec1a5f1fdea351f79b87625451ea173ccbf5abe6fca244675fcd0452872cb0025d83588dfa2526215f9053287cf8575b610f2eec6b6b944231
|
7
|
+
data.tar.gz: 714b246726fcbec24ffa397c39e980f604597302c721e86d17201f7f14d220a5f7e70ba293f3d373adcc25b8689cb6b997d156b5f0f73e3b03f3879100531ae8
|
data/README.md
CHANGED
@@ -8,15 +8,19 @@ Development tools for the SchemaPlus family of gems.
|
|
8
8
|
|
9
9
|
Provides support for working with multiple ruby versions, rails adapaters, and db versions. In particular provides a command `schema_dev` for running rspec (or whatever) on the matrix or a slice or element of it. It also auto-generates the `.travis.yml` file for [travis-ci](https://travis-ci.org) testing.
|
10
10
|
|
11
|
-
##
|
11
|
+
## Creating a new gem for the SchemaPlus family
|
12
12
|
|
13
|
-
|
13
|
+
The `schema_dev` script has a generator for new gems:
|
14
14
|
|
15
|
-
|
15
|
+
$ gem install schema_dev
|
16
|
+
$ schema_dev gem new_gem_name
|
17
|
+
|
18
|
+
Similar to `bundle gem`, this creates a skeleton structure for a new gem. The structure includes appropriate dependencies on [schema_monkey](https://github.com/SchemaPlus/schema_monkey) and on `schema_dev` itself, and creates an initial `schema_dev.yml` file, etc.
|
19
|
+
|
16
20
|
|
17
|
-
##
|
21
|
+
## Usage
|
18
22
|
|
19
|
-
|
23
|
+
### schema_dev.yml
|
20
24
|
|
21
25
|
The client gem needs a file `schema_dev.yml` in it's root, which specifies the testing matrix among other things.
|
22
26
|
|
@@ -25,39 +29,7 @@ The client gem needs a file `schema_dev.yml` in it's root, which specifies the t
|
|
25
29
|
* `db`: A single db adapter, or a list of db adapters.
|
26
30
|
* `quick`: (Optional) Hash listing the version of ruby, rails, and db to use with `--quick` option. If not specified, the default is to use the last entry in each list.
|
27
31
|
|
28
|
-
If you change this file, it's a good idea to run `schema_dev
|
29
|
-
|
30
|
-
#### Gemfiles
|
31
|
-
|
32
|
-
The client gem must contain a "gemfiles" directory containing the matrix of
|
33
|
-
possible gemfiles; It will be generated/updated automatically by the `schema_dev` script whenever you run a matrix command. You can also generate it explicitly by running
|
34
|
-
|
35
|
-
$ schema_dev gemfiles
|
36
|
-
|
37
|
-
This directory should be checked in to the git repo.
|
38
|
-
|
39
|
-
`schema_dev gemfiles` only generates gemfiles for the versions of rails &
|
40
|
-
db listed in `schema_dev.yml`. If you change the listed versions you'll
|
41
|
-
need to re-generate.
|
42
|
-
|
43
|
-
Note that generating the gemfiles blows away any previous files. If you had made
|
44
|
-
local changes for some reason, you'll need to rely on git to recover them.
|
45
|
-
|
46
|
-
|
47
|
-
#### Rspec
|
48
|
-
|
49
|
-
The client gem should include this in its `spec/spec_helper`
|
50
|
-
|
51
|
-
require 'schema_dev/rspec'
|
52
|
-
SchemaDev::Rspec.setup_db
|
53
|
-
|
54
|
-
This will take care of connecting to the test database appropriately, and will set up logging to a file specific to the test matrix cell.
|
55
|
-
|
56
|
-
#### Rake
|
57
|
-
|
58
|
-
The client gem should include this in its `Rakefile`:
|
59
|
-
|
60
|
-
require 'schema_dev/tasks'
|
32
|
+
If you change this file, it's a good idea to run `schema_dev freshen`
|
61
33
|
|
62
34
|
### Ruby selection
|
63
35
|
|
@@ -112,8 +84,49 @@ For more info, see
|
|
112
84
|
$ schema_dev help
|
113
85
|
$ schema_dev help rspec # etc.
|
114
86
|
|
115
|
-
##
|
87
|
+
## Auto-generated/updated files
|
88
|
+
|
89
|
+
Whenever you run a `schema_dev` matrix command, it first freshens the various generated files; you can also run `schema_dev freshen` manually.
|
116
90
|
|
117
|
-
|
91
|
+
### gemfiles
|
118
92
|
|
119
|
-
|
93
|
+
The client gem will contain a "gemfiles" subdirectory tree containing the matrix of
|
94
|
+
possible gemfiles; this entire tree gets created/updated automatically, and should be checked into the git repo.
|
95
|
+
|
96
|
+
Note that freshening the gemfiles happens automatically whenever you run a schema_dev matrix command, and blows away any previous files. So you should not attempt to change any files in `gemfiles/*`
|
97
|
+
|
98
|
+
If you need to include extra specifications in the Gemfile (e.g. to specify a path for a gem), you can create a file `Gemfile.local` in the project root, and its contents will be included in the Gemfile.
|
99
|
+
|
100
|
+
### .travis.yml
|
101
|
+
|
102
|
+
The `.travis.yml` file gets created automatically. Don't edit it by hand.
|
103
|
+
|
104
|
+
### README.md
|
105
|
+
|
106
|
+
`schema_dev` generates markdown describing the text matrix, and inserts it into the README.md, in a block guarded by markdown comments
|
107
|
+
|
108
|
+
[//]: # SCHEMA_DEV: MATRIX
|
109
|
+
.
|
110
|
+
.
|
111
|
+
.
|
112
|
+
[//]: # SCHEMA_DEV: MATRIX
|
113
|
+
|
114
|
+
|
115
|
+
## Behind-the-scenes
|
116
|
+
|
117
|
+
#### Rspec
|
118
|
+
|
119
|
+
The client gem's`spec/spec_helper` includes this
|
120
|
+
|
121
|
+
require 'schema_dev/rspec'
|
122
|
+
SchemaDev::Rspec.setup
|
123
|
+
|
124
|
+
This will take care of starting up `schema_monkey`, connecting to the test database appropriately, and and setting up logging to a file specific to the test matrix cell.
|
125
|
+
|
126
|
+
#### Rake
|
127
|
+
|
128
|
+
The client gem's `Rakefile` includes:
|
129
|
+
|
130
|
+
require 'schema_dev/tasks'
|
131
|
+
|
132
|
+
Which defines the rake task `create_databases` and also a task for travis-ci
|
data/bin/schema_dev
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'active_support/core_ext/hash'
|
4
4
|
require 'thor'
|
5
5
|
require_relative '../lib/schema_dev/config'
|
6
|
+
require_relative '../lib/schema_dev/gem'
|
6
7
|
require_relative '../lib/schema_dev/runner'
|
7
8
|
require_relative '../lib/schema_dev/version'
|
8
9
|
|
@@ -23,19 +24,11 @@ class CLI < Thor
|
|
23
24
|
method_option :db, type: :string, desc: "Only execute for the specified database"
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
def travis
|
28
|
-
runner.travis
|
29
|
-
end
|
30
|
-
|
31
|
-
desc "gemfiles", "create/update gemfiles/* hierarchy based on schema_dev.yml values"
|
32
|
-
def gemfiles
|
33
|
-
runner.gemfiles
|
34
|
-
end
|
27
|
+
default_task :rspec
|
35
28
|
|
36
|
-
desc "
|
37
|
-
def
|
38
|
-
runner.
|
29
|
+
desc "freshen", "update files that depend on schema_dev.yml: .travis, gemfiles/, README.md"
|
30
|
+
def freshen
|
31
|
+
runner.freshen
|
39
32
|
end
|
40
33
|
|
41
34
|
desc "matrix", "run a command over the matrix"
|
@@ -62,11 +55,15 @@ class CLI < Thor
|
|
62
55
|
runner.run('bundle', 'exec', 'rspec', args, **options.to_h.symbolize_keys)
|
63
56
|
end
|
64
57
|
|
65
|
-
|
58
|
+
desc "gem", "create a new SchemaPlus gem"
|
59
|
+
def gem(name)
|
60
|
+
SchemaDev::Gem.build(name)
|
61
|
+
end
|
66
62
|
|
67
|
-
if ARGV[0] == "--version"
|
68
|
-
puts "SchemaDev #{SchemaDev::VERSION}"
|
69
|
-
exit
|
70
63
|
end
|
71
64
|
|
72
|
-
|
65
|
+
case
|
66
|
+
when ARGV.empty? then CLI.start(["--help"])
|
67
|
+
when ARGV[0] == "--version" then puts "SchemaDev #{SchemaDev::VERSION}"
|
68
|
+
else CLI.start(ARGV)
|
69
|
+
end
|
data/lib/schema_dev/config.rb
CHANGED
@@ -16,8 +16,12 @@ module SchemaDev
|
|
16
16
|
|
17
17
|
def self._reset ; @@config = nil end # for use by rspec
|
18
18
|
|
19
|
+
def self.read
|
20
|
+
new((YAML.load Pathname.new(CONFIG_FILE).read).symbolize_keys)
|
21
|
+
end
|
22
|
+
|
19
23
|
def self.load
|
20
|
-
@@config ||=
|
24
|
+
@@config ||= read
|
21
25
|
end
|
22
26
|
|
23
27
|
def initialize(opts={}) # once we no longer support ruby 1.9.3, can switch to native keyword args
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'pathname'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
|
6
|
+
require_relative 'templates'
|
7
|
+
|
8
|
+
module SchemaDev
|
9
|
+
class Gem
|
10
|
+
def self.build(name)
|
11
|
+
new(name).build
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :gem_name, :gem_module, :gem_root, :fullname, :email
|
15
|
+
|
16
|
+
def initialize(name)
|
17
|
+
self.gem_name = name.underscore
|
18
|
+
self.gem_module = gem_name.camelize
|
19
|
+
self.gem_root = Pathname.new(gem_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def build
|
23
|
+
ensure_not_in_git
|
24
|
+
ensure_doesnt_exist
|
25
|
+
get_fullname_and_email
|
26
|
+
copy_template
|
27
|
+
self.gem_root = self.gem_root.realpath
|
28
|
+
rename_files
|
29
|
+
substitute_keys
|
30
|
+
freshen
|
31
|
+
git_init
|
32
|
+
puts <<-END.strip_heredoc
|
33
|
+
|
34
|
+
Created #{gem_name}. Your recommended next steps are:
|
35
|
+
|
36
|
+
$ cd #{gem_name}
|
37
|
+
$ bundle install
|
38
|
+
$ schema_dev bundle install
|
39
|
+
$ schema_dev rspec
|
40
|
+
END
|
41
|
+
end
|
42
|
+
|
43
|
+
def die(msg)
|
44
|
+
abort "schema_dev: #{msg}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def ensure_not_in_git
|
48
|
+
if system("git rev-parse >& /dev/null")
|
49
|
+
die "Cannot create new gem inside existing git worktree; please cd elsewhere"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def ensure_doesnt_exist
|
54
|
+
if gem_root.exist?
|
55
|
+
die "Cannot create new gem: '#{gem_root}' already exists"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_fullname_and_email
|
60
|
+
{'fullname' => 'name', 'email' => 'email' }.each do |myattr, gitattr|
|
61
|
+
if (self.send myattr+"=", `git config user.#{gitattr}`.strip).blank?
|
62
|
+
die "Who are you? Please run 'git config --global user.#{gitattr} <your-#{gitattr}>'"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def copy_template
|
68
|
+
FileUtils.cp_r Templates.root + "gem", gem_root
|
69
|
+
end
|
70
|
+
|
71
|
+
def rename_files
|
72
|
+
Dir.glob(gem_root + "**/*GEM_NAME*").each do |path|
|
73
|
+
FileUtils.mv path, path.gsub(/GEM_NAME/, gem_name)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def substitute_keys
|
78
|
+
gem_root.find.each do |path|
|
79
|
+
next unless path.file?
|
80
|
+
path.write subs(path.read)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def subs(s)
|
85
|
+
s = s.gsub('%GEM_NAME%', gem_name)
|
86
|
+
s = s.gsub('%GEM_MODULE%', gem_module)
|
87
|
+
s = s.gsub('%FULLNAME%', fullname)
|
88
|
+
s = s.gsub('%EMAIL%', email)
|
89
|
+
s = s.gsub('%SCHEMA_MONKEY_DEPENDENCY%', dependency(schema_monkey_version))
|
90
|
+
s = s.gsub('%SCHEMA_DEV_DEPENDENCY%', dependency(SchemaDev::VERSION))
|
91
|
+
s = s.gsub('%YEAR%', Time.now.strftime("%Y"))
|
92
|
+
end
|
93
|
+
|
94
|
+
def dependency(v)
|
95
|
+
major, minor, patch = v.split('.')
|
96
|
+
dep = %Q{"~> #{major}.#{minor}"}
|
97
|
+
dep += %Q{, ">= #{v}"} if patch != "0"
|
98
|
+
dep
|
99
|
+
end
|
100
|
+
|
101
|
+
def schema_monkey_version
|
102
|
+
@monkey_version ||= begin
|
103
|
+
gems = JSON.parse Faraday.get('https://rubygems.org/api/v1/versions/schema_monkey.json').body
|
104
|
+
gems.reject(&it["prerelease"]).sort_by{|g| Time.new(g["built_at"])}.last["number"]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def freshen
|
109
|
+
Dir.chdir gem_root do
|
110
|
+
Runner.new(Config.read).freshen(quiet:true)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def git_init
|
115
|
+
Dir.chdir gem_name do
|
116
|
+
system "git init"
|
117
|
+
system "git add #{gem_root.find.select(&:exist?).join(' ')}"
|
118
|
+
system "git commit -m 'Initial skeleton generated by `schema_dev gem #{gem_name}`'"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/lib/schema_dev/gemfiles.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
+
require_relative 'templates'
|
4
|
+
|
3
5
|
module SchemaDev
|
4
6
|
|
5
7
|
module Gemfiles
|
6
8
|
extend self
|
7
9
|
|
8
|
-
TEMPLATES_ROOT = Pathname.new(__FILE__).dirname.parent.parent + "templates"
|
9
|
-
|
10
10
|
def build(config)
|
11
11
|
Dir.mktmpdir do |tmpdir|
|
12
|
-
@src_root =
|
12
|
+
@src_root = Templates.root
|
13
13
|
@dst_root = Pathname.new(tmpdir).realpath
|
14
14
|
|
15
15
|
relpath = Pathname.new("gemfiles")
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module SchemaDev
|
4
|
+
class Readme
|
5
|
+
def self.update(config)
|
6
|
+
new(config.matrix).update
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :matrix, :readme
|
10
|
+
|
11
|
+
def initialize(matrix)
|
12
|
+
self.matrix = matrix
|
13
|
+
self.readme = Pathname.new('README.md')
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
return false unless readme.exist?
|
18
|
+
lines = readme.readlines
|
19
|
+
newlines = sub_matrix(lines)
|
20
|
+
if lines != newlines
|
21
|
+
readme.write newlines.join
|
22
|
+
return true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def sub_matrix(lines)
|
27
|
+
pattern = %r{^\[//\]: # SCHEMA_DEV: MATRIX}
|
28
|
+
before = lines.take_while(&it !~ pattern)
|
29
|
+
|
30
|
+
return lines if before == lines
|
31
|
+
|
32
|
+
after = lines.reverse.take_while(&it !~ pattern).reverse
|
33
|
+
|
34
|
+
contents = []
|
35
|
+
contents << "[//]: # SCHEMA_DEV: MATRIX - begin\n"
|
36
|
+
contents << "[//]: # These lines are auto-generated by schema_dev based on schema_dev.yml\n"
|
37
|
+
self.matrix.group_by(&it.slice(:ruby, :rails)).each do |pair, items|
|
38
|
+
contents << "* ruby **#{pair[:ruby]}** with rails **#{pair[:rails]}**, using #{items.map{|item| "**#{item[:db]}**"}.to_sentence(last_word_connector: ' or ')}\n"
|
39
|
+
end
|
40
|
+
contents << "\n"
|
41
|
+
contents << "[//]: # SCHEMA_DEV: MATRIX - end\n"
|
42
|
+
|
43
|
+
before + contents + after
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/schema_dev/rspec.rb
CHANGED
@@ -3,10 +3,16 @@ require_relative 'rspec/db'
|
|
3
3
|
module SchemaDev
|
4
4
|
module Rspec
|
5
5
|
|
6
|
-
def self.
|
6
|
+
def self.setup
|
7
|
+
SchemaMonkey.insert
|
7
8
|
Db.setup
|
8
9
|
end
|
9
10
|
|
11
|
+
def self.setup_db
|
12
|
+
ActiveSupport::Deprecation.warn "SchemaDev::Rspec.setup_db is deprecated. Use SchemaDev::Rspec.setup"
|
13
|
+
self.setup
|
14
|
+
end
|
15
|
+
|
10
16
|
def self.db_configuration
|
11
17
|
Db.configuration
|
12
18
|
end
|
data/lib/schema_dev/runner.rb
CHANGED
@@ -3,6 +3,7 @@ require 'shellwords'
|
|
3
3
|
require_relative 'matrix_executor'
|
4
4
|
require_relative 'travis'
|
5
5
|
require_relative 'gemfiles'
|
6
|
+
require_relative 'readme'
|
6
7
|
|
7
8
|
module SchemaDev
|
8
9
|
class Runner
|
@@ -10,21 +11,32 @@ module SchemaDev
|
|
10
11
|
@config = config
|
11
12
|
end
|
12
13
|
|
13
|
-
def travis
|
14
|
-
Travis.update(@config)
|
14
|
+
def travis(quiet: false)
|
15
|
+
if Travis.update(@config)
|
16
|
+
puts "* Updated #{Travis::TRAVIS_FILE}" unless quiet
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
|
-
def gemfiles
|
18
|
-
Gemfiles.build(@config)
|
20
|
+
def gemfiles(quiet: false)
|
21
|
+
if Gemfiles.build(@config)
|
22
|
+
puts "* Updated gemfiles" unless quiet
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
26
|
+
def readme(quiet: false)
|
27
|
+
if Readme.update(@config)
|
28
|
+
puts "* Updated README" unless quiet
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def freshen(quiet: false)
|
33
|
+
self.travis(quiet: quiet)
|
34
|
+
self.gemfiles(quiet: quiet)
|
35
|
+
self.readme(quiet: quiet)
|
24
36
|
end
|
25
37
|
|
26
38
|
def run(*args, dry_run: false, quick: false, ruby: nil, rails: nil, db: nil, freshen: true)
|
27
|
-
self.
|
39
|
+
self.freshen if freshen
|
28
40
|
|
29
41
|
matrix = MatrixExecutor.new @config.matrix(quick: quick, ruby: ruby, rails: rails, db: db)
|
30
42
|
|
data/lib/schema_dev/version.rb
CHANGED
data/lib/schema_dev.rb
CHANGED
data/schema_dev.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "activesupport"
|
22
22
|
spec.add_dependency "coveralls"
|
23
|
+
spec.add_dependency "faraday"
|
23
24
|
spec.add_dependency "fastandand"
|
24
25
|
spec.add_dependency "hash_keyword_args"
|
25
26
|
spec.add_dependency "its-it"
|
@@ -30,4 +31,5 @@ Gem::Specification.new do |spec|
|
|
30
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
33
|
spec.add_development_dependency "simplecov"
|
34
|
+
spec.add_development_dependency "webmock"
|
33
35
|
end
|
data/spec/gem_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'schema_dev/gem'
|
2
|
+
|
3
|
+
describe SchemaDev::Gem do
|
4
|
+
before(:each) do
|
5
|
+
stub_request(:get, 'https://rubygems.org/api/v1/versions/schema_monkey.json').to_return body: JSON.generate([{ built_at: Time.now, number: "0.1.2"}])
|
6
|
+
end
|
7
|
+
|
8
|
+
around(:each) do |example|
|
9
|
+
silence_stream(STDOUT) do
|
10
|
+
example.run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "creates gemspec" do
|
15
|
+
in_tmpdir do
|
16
|
+
expect{SchemaDev::Gem.build("NewGem")}.not_to raise_error
|
17
|
+
gemspec = File.read "new_gem/new_gem.gemspec"
|
18
|
+
expect(gemspec).to include %q{"schema_monkey", "~> 0.1", ">= 0.1.2"}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "complains" do
|
23
|
+
|
24
|
+
around(:each) do |example|
|
25
|
+
silence_stream(STDERR) do
|
26
|
+
example.run
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "when no git user.name" do
|
31
|
+
in_tmpdir do
|
32
|
+
expect_any_instance_of(SchemaDev::Gem).to receive(:`).with("git config user.name").and_return ""
|
33
|
+
expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /who are you/i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "when in git worktree" do
|
38
|
+
in_tmpdir do
|
39
|
+
system('git init')
|
40
|
+
expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /\bgit\b/
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "when gem directory exists" do
|
45
|
+
in_tmpdir do
|
46
|
+
FileUtils.touch "new_gem"
|
47
|
+
expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /exists/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/gemfiles_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe SchemaDev::Gemfiles do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def relevant_diff(config, dir)
|
22
|
-
src = SchemaDev::
|
22
|
+
src = SchemaDev::Templates.root + dir
|
23
23
|
diff = `diff -rq #{src} #{dir} 2>&1`.split("\n")
|
24
24
|
|
25
25
|
# expect copy not to have entry for rails not in config
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require '%GEM_NAME%/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "%GEM_NAME%"
|
8
|
+
spec.version = %GEM_MODULE%::VERSION
|
9
|
+
spec.authors = ["%FULLNAME%"]
|
10
|
+
spec.email = ["%EMAIL%"]
|
11
|
+
spec.summary = %q{TODO: Write a short summary. Required.}
|
12
|
+
spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = "https://github.com/SchemaPlus/%GEM_NAME%"
|
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_dependency "activerecord", "~> 4.2"
|
22
|
+
spec.add_dependency "schema_monkey", %SCHEMA_MONKEY_DEPENDENCY%
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0.0"
|
27
|
+
spec.add_development_dependency "schema_dev", %SCHEMA_DEV_DEPENDENCY%
|
28
|
+
spec.add_development_dependency "simplecov"
|
29
|
+
spec.add_development_dependency "simplecov-gem-profile"
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) %YEAR% %FULLNAME%
|
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.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
[](http://badge.fury.io/rb/%GEM_NAME%)
|
2
|
+
[](http://travis-ci.org/SchemaPlus/%GEM_NAME%)
|
3
|
+
[](https://coveralls.io/r/SchemaPlus/%GEM_NAME%)
|
4
|
+
[](https://gemnasium.com/SchemaPlus/%GEM_NAME%)
|
5
|
+
|
6
|
+
# %GEM_NAME%
|
7
|
+
|
8
|
+
TODO: Write a gem description
|
9
|
+
|
10
|
+
%GEM_NAME% is part of the [SchemaPlus](https://github.com/SchemaPlus/) family of Ruby on Rails extension gems.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
In your application's Gemfile
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "%GEM_NAME%"
|
18
|
+
```
|
19
|
+
## Compatibility
|
20
|
+
|
21
|
+
%GEM_NAME% is tested on
|
22
|
+
|
23
|
+
[//]: # SCHEMA_DEV: MATRIX
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
|
30
|
+
## History
|
31
|
+
|
32
|
+
* See [CHANGELOG](CHANGELOG.md) for per-version release notes.
|
33
|
+
|
34
|
+
## Development & Testing
|
35
|
+
|
36
|
+
Are you interested in contributing to %GEM_NAME%? Thanks! Please follow
|
37
|
+
the standard protocol: fork, feature branch, develop, push, and issue pull request.
|
38
|
+
|
39
|
+
Some things to know about to help you develop and test:
|
40
|
+
|
41
|
+
* **schema_dev**: %GEM_NAME% uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
42
|
+
facilitate running rspec tests on the matrix of ruby, rails, and database
|
43
|
+
versions that the gem supports, both locally and on
|
44
|
+
[travis-ci](http://travis-ci.org/SchemaPlus/%GEM_NAME%)
|
45
|
+
|
46
|
+
To to run rspec locally on the full matrix, do:
|
47
|
+
|
48
|
+
$ schema_dev bundle install
|
49
|
+
$ schema_dev rspec
|
50
|
+
|
51
|
+
You can also run on just one configuration at a time; For info, see `schema_dev --help` or the
|
52
|
+
[schema_dev](https://github.com/SchemaPlus/schema_dev) README.
|
53
|
+
|
54
|
+
The matrix of configurations is specified in `schema_dev.yml` in
|
55
|
+
the project root.
|
56
|
+
|
57
|
+
* **schema_monkey**: %GEM_NAME% extends ActiveRecord using
|
58
|
+
[schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s extension
|
59
|
+
API and protocols -- see its README for details. If your contribution needs any additional monkey patching
|
60
|
+
that isn't already supported by
|
61
|
+
[schema_monkey](https://github.com/SchemaPlus/schema_monkey), please head
|
62
|
+
over there and submit a PR.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'schema_monkey'
|
2
|
+
|
3
|
+
# Load any mixins to ActiveRecord modules, such as:
|
4
|
+
#
|
5
|
+
# require_relative '%GEM_NAME%/active_record/base'
|
6
|
+
# require_relative '%GEM_NAME%/active_record/connection_adapters/abstract_adapter'
|
7
|
+
#
|
8
|
+
# Any modules named %GEM_MODULE%::ActiveRecord::<remainder-of-submodule-path>
|
9
|
+
# will be automatically #include'd in their counterparts in ::ActiveRecord
|
10
|
+
|
11
|
+
|
12
|
+
# Load any middleware, such as:
|
13
|
+
#
|
14
|
+
# require_relative '%GEM_NAME%/middleware/model'
|
15
|
+
#
|
16
|
+
# Any modules named %GEM_MODULE%::Middleware::<submodule-path> will
|
17
|
+
# automatically have their .insert method called.
|
18
|
+
|
19
|
+
# Database adapter-specific mixin, if any, will automatically #include'd in
|
20
|
+
# its counterpart depending on which database adapter is in use.
|
21
|
+
module %GEM_MODULE%
|
22
|
+
module ActiveRecord
|
23
|
+
module ConnectionAdapters
|
24
|
+
# autoload :MysqlAdapter, 'schema_plus_tables/active_record/connection_adapters/mysql_adapter'
|
25
|
+
# autoload :PostgresqlAdapter, 'schema_plus_tables/active_record/connection_adapters/postgresql_adapter'
|
26
|
+
# autoload :Sqlite3Adapter, 'schema_plus_tables/active_record/connection_adapters/sqlite3_adapter'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
# Extra load-time initialization can go here. You can delete this if you don't have any.
|
34
|
+
module %GEM_MODULE%
|
35
|
+
def self.insert
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
SchemaMonkey.register(%GEM_MODULE%)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
# A basic sanity check to have as a spec when first starting. Feel free to delete this
|
5
|
+
# once you've got real content.
|
6
|
+
|
7
|
+
describe "Sanity Check" do
|
8
|
+
|
9
|
+
it "database is connected" do
|
10
|
+
expect(ActiveRecord::Base).to be_connected
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-gem-profile'
|
3
|
+
SimpleCov.start "gem"
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
|
8
|
+
require 'rspec'
|
9
|
+
require 'active_record'
|
10
|
+
require '%GEM_NAME%'
|
11
|
+
require 'schema_dev/rspec'
|
12
|
+
|
13
|
+
SchemaDev::Rspec.setup
|
14
|
+
|
15
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.warnings = true
|
19
|
+
end
|
20
|
+
|
21
|
+
SimpleCov.command_name "[ruby #{RUBY_VERSION} - ActiveRecord #{::ActiveRecord::VERSION::STRING} - #{ActiveRecord::Base.connection.adapter_name}]"
|
22
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_dev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: fastandand
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +178,20 @@ dependencies:
|
|
164
178
|
- - ">="
|
165
179
|
- !ruby/object:Gem::Version
|
166
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: webmock
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
167
195
|
description: SchemaPlus development tools
|
168
196
|
email:
|
169
197
|
- ronen@barzel.org
|
@@ -183,9 +211,11 @@ files:
|
|
183
211
|
- lib/schema_dev.rb
|
184
212
|
- lib/schema_dev/config.rb
|
185
213
|
- lib/schema_dev/executor.rb
|
214
|
+
- lib/schema_dev/gem.rb
|
186
215
|
- lib/schema_dev/gemfile_selector.rb
|
187
216
|
- lib/schema_dev/gemfiles.rb
|
188
217
|
- lib/schema_dev/matrix_executor.rb
|
218
|
+
- lib/schema_dev/readme.rb
|
189
219
|
- lib/schema_dev/rspec.rb
|
190
220
|
- lib/schema_dev/rspec/db.rb
|
191
221
|
- lib/schema_dev/ruby_selector.rb
|
@@ -193,15 +223,28 @@ files:
|
|
193
223
|
- lib/schema_dev/tasks.rb
|
194
224
|
- lib/schema_dev/tasks/coveralls.rb
|
195
225
|
- lib/schema_dev/tasks/dbms.rb
|
226
|
+
- lib/schema_dev/templates.rb
|
196
227
|
- lib/schema_dev/travis.rb
|
197
228
|
- lib/schema_dev/version.rb
|
198
229
|
- schema_dev.gemspec
|
199
230
|
- spec/config_spec.rb
|
231
|
+
- spec/gem_spec.rb
|
200
232
|
- spec/gemfile_sepector_spec.rb
|
201
233
|
- spec/gemfiles_spec.rb
|
202
234
|
- spec/runner_spec.rb
|
203
235
|
- spec/spec_helper.rb
|
204
236
|
- spec/travis_spec.rb
|
237
|
+
- templates/gem/.gitignore
|
238
|
+
- templates/gem/GEM_NAME.gemspec
|
239
|
+
- templates/gem/Gemfile
|
240
|
+
- templates/gem/LICENSE.txt
|
241
|
+
- templates/gem/README.md
|
242
|
+
- templates/gem/Rakefile
|
243
|
+
- templates/gem/lib/GEM_NAME.rb
|
244
|
+
- templates/gem/lib/GEM_NAME/version.rb
|
245
|
+
- templates/gem/schema_dev.yml
|
246
|
+
- templates/gem/spec/sanity_spec.rb
|
247
|
+
- templates/gem/spec/spec_helper.rb
|
205
248
|
- templates/gemfiles/Gemfile.base
|
206
249
|
- templates/gemfiles/rails-3.2/Gemfile.base
|
207
250
|
- templates/gemfiles/rails-3.2/Gemfile.mysql
|
@@ -250,6 +293,7 @@ specification_version: 4
|
|
250
293
|
summary: SchemaPlus development tools
|
251
294
|
test_files:
|
252
295
|
- spec/config_spec.rb
|
296
|
+
- spec/gem_spec.rb
|
253
297
|
- spec/gemfile_sepector_spec.rb
|
254
298
|
- spec/gemfiles_spec.rb
|
255
299
|
- spec/runner_spec.rb
|