schema_dev 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema_dev/gem.rb +39 -6
- data/lib/schema_dev/version.rb +1 -1
- data/schema_dev.gemspec +1 -0
- data/spec/gem_spec.rb +52 -43
- data/spec/spec_helper.rb +1 -0
- data/templates/gem/GEM_NAME.gemspec +2 -2
- data/templates/gem/lib/GEM_BASE_NAME.rb +13 -0
- data/templates/gem/lib/{GEM_NAME → GEM_BASE_NAME}/version.rb +0 -0
- metadata +18 -4
- data/templates/gem/lib/GEM_NAME.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3dae5713b925a353bc74bb7b9783670586f350c
|
4
|
+
data.tar.gz: 73f1a0ab7b0e913d31311c4296b97e7847ed00de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6d02ba2491b08e1177caf97fdd455853b9f37a887a2537bf8bcf1f44c24528da5f188bb1734e10a13da7a182caf1ba0d1b2d95e065e22da39b3a008d326ae7
|
7
|
+
data.tar.gz: f806f3e86dd8eb20e9d8ab6ec57de80db8c508d67b57de47d9174e18a81f178d0d203a9ec832da86290c67b1724b868ec92fa58acfab957691de9e44a98de0b6
|
data/lib/schema_dev/gem.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'json'
|
2
3
|
require 'fileutils'
|
3
4
|
require 'pathname'
|
4
5
|
require 'active_support/core_ext/string'
|
5
6
|
|
7
|
+
require_relative 'runner'
|
6
8
|
require_relative 'templates'
|
7
9
|
|
8
10
|
module SchemaDev
|
@@ -11,12 +13,24 @@ module SchemaDev
|
|
11
13
|
new(name).build
|
12
14
|
end
|
13
15
|
|
14
|
-
attr_accessor :gem_name, :gem_module, :gem_root, :fullname, :email
|
16
|
+
attr_accessor :gem_name, :gem_module, :gem_root, :gem_parent_name, :gem_base_name, :gem_lib_path, :fullname, :email
|
15
17
|
|
16
18
|
def initialize(name)
|
17
19
|
self.gem_name = name.underscore
|
18
|
-
self.gem_module = gem_name.camelize.sub(/^SchemaPlus(?=\w+)/, 'SchemaPlus::')
|
19
20
|
self.gem_root = Pathname.new(gem_name)
|
21
|
+
if gem_name =~ /^(schema_plus)_(.*)/
|
22
|
+
parent, base = [$1, $2]
|
23
|
+
self.gem_module = [parent, base].map(&:camelize).join('::')
|
24
|
+
self.gem_lib_path = [parent, base].join('/')
|
25
|
+
self.gem_parent_name = parent
|
26
|
+
self.gem_base_name = base
|
27
|
+
@subdir = true
|
28
|
+
else
|
29
|
+
self.gem_module = gem_name.camelize
|
30
|
+
self.gem_lib_path = gem_name
|
31
|
+
self.gem_base_name = gem_name
|
32
|
+
@subdir = false
|
33
|
+
end
|
20
34
|
get_fullname_and_email
|
21
35
|
end
|
22
36
|
|
@@ -26,6 +40,7 @@ module SchemaDev
|
|
26
40
|
copy_template
|
27
41
|
self.gem_root = self.gem_root.realpath
|
28
42
|
rename_files
|
43
|
+
fixup_subdir if @subdir
|
29
44
|
substitute_keys
|
30
45
|
freshen
|
31
46
|
git_init
|
@@ -73,6 +88,22 @@ module SchemaDev
|
|
73
88
|
Dir.glob(gem_root + "**/*GEM_NAME*").each do |path|
|
74
89
|
FileUtils.mv path, path.gsub(/GEM_NAME/, gem_name)
|
75
90
|
end
|
91
|
+
Dir.glob(gem_root + "**/*GEM_BASE_NAME*").each do |path|
|
92
|
+
FileUtils.mv path, path.gsub(/GEM_BASE_NAME/, gem_base_name)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def fixup_subdir
|
97
|
+
libdir = gem_root + "lib"
|
98
|
+
aside = libdir.to_s + "x"
|
99
|
+
subdir = libdir + gem_parent_name
|
100
|
+
|
101
|
+
FileUtils.mv libdir, aside
|
102
|
+
libdir.mkpath
|
103
|
+
FileUtils.mv aside, subdir
|
104
|
+
(gem_root + "lib" + "#{gem_name}.rb").write <<-END.lstrip
|
105
|
+
require_relative '#{gem_parent_name}/#{gem_base_name}.rb'
|
106
|
+
END
|
76
107
|
end
|
77
108
|
|
78
109
|
def substitute_keys
|
@@ -84,10 +115,12 @@ module SchemaDev
|
|
84
115
|
|
85
116
|
def subs(s)
|
86
117
|
s = s.gsub('%GEM_NAME%', gem_name)
|
118
|
+
s = s.gsub('%GEM_BASE_NAME%', gem_base_name)
|
119
|
+
s = s.gsub('%GEM_LIB_PATH%', gem_lib_path)
|
87
120
|
s = s.gsub('%GEM_MODULE%', gem_module)
|
88
121
|
s = s.gsub('%FULLNAME%', fullname)
|
89
122
|
s = s.gsub('%EMAIL%', email)
|
90
|
-
s = s.gsub('%
|
123
|
+
s = s.gsub('%SCHEMA_PLUS_CORE_DEPENDENCY%', dependency(schema_plus_core_version))
|
91
124
|
s = s.gsub('%SCHEMA_DEV_DEPENDENCY%', dependency(SchemaDev::VERSION))
|
92
125
|
s = s.gsub('%YEAR%', Time.now.strftime("%Y"))
|
93
126
|
end
|
@@ -99,9 +132,9 @@ module SchemaDev
|
|
99
132
|
dep
|
100
133
|
end
|
101
134
|
|
102
|
-
def
|
103
|
-
@
|
104
|
-
gems = JSON.parse Faraday.get('https://rubygems.org/api/v1/versions/
|
135
|
+
def schema_plus_core_version
|
136
|
+
@core_version ||= begin
|
137
|
+
gems = JSON.parse Faraday.get('https://rubygems.org/api/v1/versions/schema_plus_core.json').body
|
105
138
|
gems.reject(&it["prerelease"]).sort_by(&it["number"].split('.')).last["number"]
|
106
139
|
end
|
107
140
|
end
|
data/lib/schema_dev/version.rb
CHANGED
data/schema_dev.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.7"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_development_dependency "rspec-given"
|
33
34
|
spec.add_development_dependency "simplecov"
|
34
35
|
spec.add_development_dependency "webmock"
|
35
36
|
end
|
data/spec/gem_spec.rb
CHANGED
@@ -2,63 +2,72 @@ require 'schema_dev/gem'
|
|
2
2
|
|
3
3
|
describe SchemaDev::Gem do
|
4
4
|
|
5
|
-
let(:user_name) { "My Name" }
|
6
|
-
let(:user_email) { "my_name@example.com" }
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/schema_monkey.json').to_return body: JSON.generate([
|
10
|
-
{ number: "1.0.0.pre", prerelease: true},
|
11
|
-
{ number: "0.2.1"},
|
12
|
-
{ number: "0.1.2"},
|
13
|
-
{ number: "0.1.1" },
|
14
|
-
])
|
15
|
-
allow_any_instance_of(SchemaDev::Gem).to receive(:`).with("git config user.name").and_return user_name
|
16
|
-
allow_any_instance_of(SchemaDev::Gem).to receive(:`).with("git config user.email").and_return user_email
|
17
|
-
end
|
18
|
-
|
19
5
|
around(:each) do |example|
|
20
6
|
silence_stream(STDOUT) do
|
21
|
-
|
7
|
+
silence_stream(STDERR) do
|
8
|
+
in_tmpdir do
|
9
|
+
example.run
|
10
|
+
end
|
11
|
+
end
|
22
12
|
end
|
23
13
|
end
|
24
14
|
|
25
|
-
|
26
|
-
|
27
|
-
expect{SchemaDev::Gem.build("NewGem")}.not_to raise_error
|
28
|
-
gemspec = File.read "new_gem/new_gem.gemspec"
|
29
|
-
expect(gemspec).to include %q{"schema_monkey", "~> 0.2", ">= 0.2.1"}
|
30
|
-
expect(gemspec).to match(/authors.*#{user_name}/)
|
31
|
-
expect(gemspec).to match(/email.*#{user_email}/)
|
32
|
-
end
|
33
|
-
end
|
15
|
+
Given(:user_name) { "My Name" }
|
16
|
+
Given(:user_email) { "my_name@example.com" }
|
34
17
|
|
35
|
-
|
18
|
+
Given {
|
19
|
+
allow_any_instance_of(SchemaDev::Gem).to receive(:`).with("git config user.name").and_return user_name
|
20
|
+
allow_any_instance_of(SchemaDev::Gem).to receive(:`).with("git config user.email").and_return user_email
|
21
|
+
}
|
36
22
|
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
context "builds" do
|
24
|
+
|
25
|
+
Given {
|
26
|
+
stub_request(:get, 'https://rubygems.org/api/v1/versions/schema_plus_core.json').to_return body: JSON.generate([
|
27
|
+
{ number: "1.0.0.pre", prerelease: true},
|
28
|
+
{ number: "0.2.1"},
|
29
|
+
{ number: "0.1.2"},
|
30
|
+
{ number: "0.1.1" },
|
31
|
+
])
|
32
|
+
}
|
33
|
+
|
34
|
+
When { SchemaDev::Gem.build gem_name }
|
35
|
+
|
36
|
+
When(:gemspec) { File.read "#{gem_name}/#{gem_name}.gemspec" }
|
37
|
+
|
38
|
+
Invariant { expect(gemspec).to include %q{"schema_plus_core", "~> 0.2", ">= 0.2.1"} }
|
39
|
+
Invariant { expect(gemspec).to match %r{authors.*#{user_name}} }
|
40
|
+
Invariant { expect(gemspec).to match %r{email.*#{user_email}} }
|
41
|
+
|
42
|
+
context "flat gem" do
|
43
|
+
Given(:gem_name) { "new_gem" }
|
44
|
+
Then { expect(gemspec).to include %q{require 'new_gem/version'} }
|
45
|
+
Then { expect(File.read "new_gem/lib/new_gem.rb").to include %q{SchemaMonkey.register NewGem} }
|
40
46
|
end
|
41
|
-
end
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
expect
|
48
|
+
context "subdir gem" do
|
49
|
+
Given(:gem_name) { "schema_plus_new_gem" }
|
50
|
+
Then { expect(gemspec).to include %q{require 'schema_plus/new_gem/version'} }
|
51
|
+
Then { expect(File.read "schema_plus_new_gem/lib/schema_plus_new_gem.rb").to include %q{require_relative 'schema_plus/new_gem.rb'} }
|
52
|
+
Then { expect(File.read "schema_plus_new_gem/lib/schema_plus/new_gem.rb").to include %q{SchemaMonkey.register SchemaPlus::NewGem} }
|
47
53
|
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "complains" do
|
57
|
+
|
58
|
+
context "when no git user.name" do
|
59
|
+
Given(:user_name) { "" }
|
60
|
+
Then { expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /who are you/i }
|
48
61
|
end
|
49
62
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /\bgit\b/
|
54
|
-
end
|
63
|
+
context "when in git worktree" do
|
64
|
+
Given { expect_any_instance_of(SchemaDev::Gem).to receive(:system).with(/^git rev-parse/).and_return true }
|
65
|
+
Then { expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /\bgit\b/ }
|
55
66
|
end
|
56
67
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /exists/
|
61
|
-
end
|
68
|
+
context "when gem directory exists" do
|
69
|
+
Given { FileUtils.touch "new_gem" }
|
70
|
+
Then { expect{SchemaDev::Gem.build("NewGem")}.to raise_error SystemExit, /exists/ }
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '%
|
4
|
+
require '%GEM_LIB_PATH%/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "%GEM_NAME%"
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
21
|
gem.add_dependency "activerecord", "~> 4.2"
|
22
|
-
gem.add_dependency "
|
22
|
+
gem.add_dependency "schema_plus_core", %SCHEMA_PLUS_CORE_DEPENDENCY%
|
23
23
|
|
24
24
|
gem.add_development_dependency "bundler", "~> 1.7"
|
25
25
|
gem.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'schema_plus/core'
|
2
|
+
|
3
|
+
require_relative '%GEM_BASE_NAME%/version'
|
4
|
+
|
5
|
+
# Load any mixins to ActiveRecord modules, such as:
|
6
|
+
#
|
7
|
+
#require_relative '%GEM_BASE_NAME%/active_record/base'
|
8
|
+
|
9
|
+
# Load any middleware, such as:
|
10
|
+
#
|
11
|
+
# require_relative '%GEM_BASE_NAME%/middleware/model'
|
12
|
+
|
13
|
+
SchemaMonkey.register %GEM_MODULE%
|
File without changes
|
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: 3.
|
4
|
+
version: 3.2.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-02-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '3.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rspec-given
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: simplecov
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -245,8 +259,8 @@ files:
|
|
245
259
|
- templates/gem/README.md
|
246
260
|
- templates/gem/Rakefile
|
247
261
|
- templates/gem/gitignore
|
248
|
-
- templates/gem/lib/
|
249
|
-
- templates/gem/lib/
|
262
|
+
- templates/gem/lib/GEM_BASE_NAME.rb
|
263
|
+
- templates/gem/lib/GEM_BASE_NAME/version.rb
|
250
264
|
- templates/gem/schema_dev.yml
|
251
265
|
- templates/gem/spec/sanity_spec.rb
|
252
266
|
- templates/gem/spec/spec_helper.rb
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'schema_monkey'
|
2
|
-
|
3
|
-
require_relative '%GEM_NAME%/version'
|
4
|
-
|
5
|
-
|
6
|
-
# Load any mixins to ActiveRecord modules, such as:
|
7
|
-
#
|
8
|
-
# require_relative '%GEM_NAME%/active_record/base'
|
9
|
-
# require_relative '%GEM_NAME%/active_record/connection_adapters/abstract_adapter'
|
10
|
-
#
|
11
|
-
# Any modules named %GEM_MODULE%::ActiveRecord::<remainder-of-submodule-path>
|
12
|
-
# will be automatically #include'd in their counterparts in ::ActiveRecord
|
13
|
-
|
14
|
-
|
15
|
-
# Load any middleware, such as:
|
16
|
-
#
|
17
|
-
# require_relative '%GEM_NAME%/middleware/model'
|
18
|
-
#
|
19
|
-
# Any modules named %GEM_MODULE%::Middleware::<submodule-path> will
|
20
|
-
# automatically have their .insert method called.
|
21
|
-
|
22
|
-
|
23
|
-
# Database adapter-specific mixin, if any, will automatically #include'd in
|
24
|
-
# its counterpart depending on which database adapter is in use.
|
25
|
-
module %GEM_MODULE%
|
26
|
-
module ActiveRecord
|
27
|
-
module ConnectionAdapters
|
28
|
-
# autoload :MysqlAdapter, 'schema_plus_tables/active_record/connection_adapters/mysql_adapter'
|
29
|
-
# autoload :PostgresqlAdapter, 'schema_plus_tables/active_record/connection_adapters/postgresql_adapter'
|
30
|
-
# autoload :Sqlite3Adapter, 'schema_plus_tables/active_record/connection_adapters/sqlite3_adapter'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
# Extra load-time initialization can go here. You can delete this if you don't have any.
|
37
|
-
module %GEM_MODULE%
|
38
|
-
def self.insert
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
SchemaMonkey.register(%GEM_MODULE%)
|