stimpack 0.5.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -0
- data/bin/tapioca +29 -0
- data/lib/stimpack/integrations/factory_bot.rb +2 -2
- data/lib/stimpack/integrations/rails.rb +39 -3
- data/lib/stimpack/integrations/rspec.rb +38 -11
- data/lib/stimpack/pack/configuration.rb +7 -1
- data/lib/stimpack/pack.rb +6 -31
- data/lib/stimpack/packs.rb +24 -19
- data/lib/stimpack/railtie.rb +6 -2
- data/lib/stimpack/rspec.rb +3 -0
- data/lib/stimpack/version.rb +1 -1
- data/lib/stimpack.rb +3 -10
- metadata +79 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be1d3fa462f2ec696d5c72721fd96cead8a0bb2c08f238f2ffab9af6ce753ea9
|
4
|
+
data.tar.gz: 2a09c371fea45fca32c6d386ec6588887a04326ee306b81199edeb7e4ffa2cb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56a878d5ccc64a91ab8366759d6900758e80a59f0a4ad60b8c8397849e975f2043e46926bff5ac6ec1745aad5d69fd78ba5cc7dcce2242f45aeb374a5483863a
|
7
|
+
data.tar.gz: 8767f7b944326da96773793170b32b5e880bfebc1ad0e8ab657e2d84154a874c9a50603ebd0c1e9e5bd4fead7c13810e5e93e10e6072e40e99fa9485d550fa09
|
data/README.md
CHANGED
@@ -92,6 +92,35 @@ metadata:
|
|
92
92
|
engine: true
|
93
93
|
```
|
94
94
|
|
95
|
+
### RSpec Integration
|
96
|
+
Simply add `--require stimpack/rspec` to your `.rspec`.
|
97
|
+
Or, if you'd like, pass it as an argument to `rspec`:
|
98
|
+
|
99
|
+
```
|
100
|
+
$ rspec --require stimpack/rspec ...
|
101
|
+
```
|
102
|
+
|
103
|
+
Integration will allow you to run tests as such:
|
104
|
+
```
|
105
|
+
# Run all specs in your entire application (packs and all):
|
106
|
+
rspec
|
107
|
+
|
108
|
+
# Run just that one test:
|
109
|
+
rspec spec/some/specific_spec.rb
|
110
|
+
|
111
|
+
# Run all tests under the "foobar" pack and all the tests of its nested packs:
|
112
|
+
rspec packs/foobar
|
113
|
+
|
114
|
+
# Same as above but also adds the "binbaz" pack:
|
115
|
+
rspec packs/foobar pack/binbaz
|
116
|
+
|
117
|
+
# Run all test files inside the "packs/foobar/spec" directory:
|
118
|
+
rspec packs/foobar/spec
|
119
|
+
|
120
|
+
# Run all specs under the "packs/foobar/nested_pack" pack:
|
121
|
+
rspec packs/foobar/nested_pack
|
122
|
+
```
|
123
|
+
|
95
124
|
## Contributing
|
96
125
|
|
97
126
|
Bug reports and pull requests are welcome on GitHub at https://github.com/Gusto/stimpack.
|
data/bin/tapioca
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'tapioca' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("tapioca", "tapioca")
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Stimpack
|
2
2
|
module Integrations
|
3
3
|
class FactoryBot
|
4
|
-
def
|
4
|
+
def initialize(app)
|
5
5
|
return unless app.config.respond_to?(:factory_bot)
|
6
6
|
|
7
|
-
Packs.each do |pack|
|
7
|
+
Packs.all.each do |pack|
|
8
8
|
app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
|
9
9
|
end
|
10
10
|
end
|
@@ -1,17 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/inflections"
|
4
|
+
|
3
5
|
module Stimpack
|
4
6
|
module Integrations
|
5
7
|
class Rails
|
6
|
-
def
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
|
7
11
|
Stimpack.config.paths.freeze
|
12
|
+
create_engines
|
13
|
+
inject_paths
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_engines
|
17
|
+
Packs.all.each do |pack|
|
18
|
+
next unless pack.config.engine?
|
19
|
+
|
20
|
+
pack.engine = create_engine(pack)
|
21
|
+
end
|
22
|
+
end
|
8
23
|
|
9
|
-
|
24
|
+
def inject_paths
|
25
|
+
Packs.all.each do |pack|
|
10
26
|
Stimpack.config.paths.each do |path|
|
11
|
-
app.paths[path] << pack.path.join(path)
|
27
|
+
@app.paths[path] << pack.path.join(path)
|
12
28
|
end
|
13
29
|
end
|
14
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def create_namespace(name)
|
35
|
+
namespace = ActiveSupport::Inflector.camelize(name)
|
36
|
+
namespace.split("::").reduce(Object) do |base, mod|
|
37
|
+
if base.const_defined?(mod, false)
|
38
|
+
base.const_get(mod, false)
|
39
|
+
else
|
40
|
+
base.const_set(mod, Module.new)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_engine(pack)
|
46
|
+
name = pack.path.relative_path_from(Stimpack::Packs.root)
|
47
|
+
namespace = create_namespace(pack.name)
|
48
|
+
stim = Stim.new(pack, namespace)
|
49
|
+
namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
|
50
|
+
end
|
15
51
|
end
|
16
52
|
end
|
17
53
|
end
|
@@ -1,19 +1,46 @@
|
|
1
1
|
module Stimpack
|
2
2
|
module Integrations
|
3
3
|
class RSpec
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# doesn't mean that we've loaded rspec-core, or even about to run tests.
|
9
|
-
# Let's make sure we are actually loading the test environment before
|
10
|
-
# installing our integration. An easy of doing this is seeing of the
|
11
|
-
# configuration method exists on RSpec.
|
12
|
-
return unless ::RSpec.respond_to?(:configuration)
|
4
|
+
def initialize
|
5
|
+
# This is the list of directories RSpec was told to run.
|
6
|
+
to_run = ::RSpec.configuration.instance_variable_get(:@files_or_directories_to_run)
|
7
|
+
default_path = ::RSpec.configuration.default_path
|
13
8
|
|
14
|
-
|
15
|
-
|
9
|
+
if to_run == [default_path]
|
10
|
+
# This is the default case when you run `rspec`. We want to add all the pack's spec paths
|
11
|
+
# to the collection of directories to run.
|
12
|
+
|
13
|
+
pack_paths = Packs.all.map do |pack|
|
14
|
+
spec_path = pack.relative_path.join(default_path)
|
15
|
+
spec_path.to_s if spec_path.exist?
|
16
|
+
end
|
17
|
+
|
18
|
+
to_run.concat(pack_paths)
|
19
|
+
else
|
20
|
+
# This is when `rspec` is run with a list of directories or files. We scan this list to see
|
21
|
+
# if any of them matches a pack's directory. If it does, we concat the `default_path` to the
|
22
|
+
# end of it.
|
23
|
+
#
|
24
|
+
# packs/my_pack => packs/my_pack/spec
|
25
|
+
#
|
26
|
+
# If it doesn't match a pack path, we leave it alone.
|
27
|
+
|
28
|
+
to_run.map! do |path|
|
29
|
+
if pack = Packs.all_by_path[path]
|
30
|
+
[
|
31
|
+
pack,
|
32
|
+
*Packs.all(pack)
|
33
|
+
].map do |pack|
|
34
|
+
spec_path = pack.relative_path.join(default_path)
|
35
|
+
spec_path.to_s if spec_path.exist?
|
36
|
+
end
|
37
|
+
else
|
38
|
+
path
|
39
|
+
end
|
40
|
+
end
|
16
41
|
end
|
42
|
+
|
43
|
+
::RSpec.configuration.files_or_directories_to_run = to_run.flatten.compact.uniq
|
17
44
|
end
|
18
45
|
end
|
19
46
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "yaml"
|
4
|
+
|
3
5
|
module Stimpack
|
4
6
|
class Pack
|
5
7
|
class Configuration
|
@@ -17,7 +19,11 @@ module Stimpack
|
|
17
19
|
private
|
18
20
|
|
19
21
|
def data
|
20
|
-
@data ||=
|
22
|
+
@data ||= begin
|
23
|
+
contents = YAML.respond_to?(:safe_load_file) ? YAML.safe_load_file(@path) : YAML.load_file(@path)
|
24
|
+
contents ||= {}
|
25
|
+
contents.fetch(KEY, {}).freeze
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
data/lib/stimpack/pack.rb
CHANGED
@@ -1,53 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "pathname"
|
4
|
+
|
3
5
|
module Stimpack
|
4
6
|
class Pack
|
5
7
|
PACKAGE_FILE = "package.yml"
|
6
8
|
|
7
9
|
autoload :Configuration, "stimpack/pack/configuration"
|
8
10
|
|
9
|
-
attr_reader :name
|
10
11
|
attr_reader :path
|
11
|
-
attr_reader :
|
12
|
-
|
13
|
-
def self.create(path)
|
14
|
-
new(path) if path.join(PACKAGE_FILE).exist?
|
15
|
-
end
|
12
|
+
attr_reader :name
|
13
|
+
attr_accessor :engine
|
16
14
|
|
17
15
|
def initialize(path)
|
18
16
|
@path = path
|
19
|
-
@name = path.
|
20
|
-
|
21
|
-
if config.engine?
|
22
|
-
@engine = create_engine
|
23
|
-
end
|
17
|
+
@name = path.basename.to_s
|
24
18
|
end
|
25
19
|
|
26
20
|
def relative_path
|
27
|
-
@relative_path ||= path.relative_path_from(
|
21
|
+
@relative_path ||= path.relative_path_from(Stimpack.root)
|
28
22
|
end
|
29
23
|
|
30
24
|
def config
|
31
25
|
@config ||= Configuration.new(path.join(PACKAGE_FILE))
|
32
26
|
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def create_engine
|
37
|
-
namespace = create_namespace(name)
|
38
|
-
stim = Stim.new(self, namespace)
|
39
|
-
namespace.const_set("Engine", Class.new(Rails::Engine)).include(stim)
|
40
|
-
end
|
41
|
-
|
42
|
-
def create_namespace(name)
|
43
|
-
namespace = ActiveSupport::Inflector.camelize(name)
|
44
|
-
namespace.split("::").reduce(Object) do |base, mod|
|
45
|
-
if base.const_defined?(mod)
|
46
|
-
base.const_get(mod)
|
47
|
-
else
|
48
|
-
base.const_set(mod, Module.new)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
27
|
end
|
53
28
|
end
|
data/lib/stimpack/packs.rb
CHANGED
@@ -1,42 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support"
|
4
|
-
require "pathname"
|
5
|
-
require "rails"
|
6
4
|
|
7
5
|
module Stimpack
|
8
6
|
module Packs
|
7
|
+
PACKAGE_GLOB_PATTERN = "*/#{Pack::PACKAGE_FILE}"
|
8
|
+
|
9
9
|
class << self
|
10
10
|
def root
|
11
|
-
@root ||=
|
11
|
+
@root ||= Stimpack.root.join(Stimpack.config.root)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def find(path)
|
15
|
+
@find_pack_paths ||= all_by_path.keys.sort_by(&:length).reverse!.map { |path| "#{path}/" }
|
16
|
+
path = "#{path}/"
|
17
|
+
@find_pack_paths.find do |pack_path|
|
18
|
+
path.start_with?(pack_path)
|
19
19
|
end
|
20
|
-
@packs.freeze
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
22
|
+
def all(parent = nil)
|
23
|
+
@all ||= resolve(root).each_with_object({}) do |pack, map|
|
24
|
+
map[pack] = resolve(pack.path).freeze
|
25
|
+
end.freeze
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
if parent
|
28
|
+
@all[parent]
|
29
|
+
else
|
30
|
+
@all.keys + @all.values.flatten
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
32
|
-
@
|
34
|
+
def all_by_path
|
35
|
+
@all_by_path ||= all.each_with_object({}) do |pack, map|
|
36
|
+
map[pack.relative_path.to_s] = pack
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
|
-
|
36
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def resolve(directory)
|
43
|
+
directory.glob(PACKAGE_GLOB_PATTERN).map { |path| Pack.new(path.dirname) }
|
37
44
|
end
|
38
45
|
end
|
39
|
-
|
40
|
-
@packs = {}
|
41
46
|
end
|
42
47
|
end
|
data/lib/stimpack/railtie.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
require "rails"
|
1
|
+
require "rails/railtie"
|
2
2
|
|
3
3
|
module Stimpack
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
config.before_configuration do |app|
|
6
|
-
|
6
|
+
Integrations::Rails.new(app)
|
7
|
+
Integrations::FactoryBot.new(app)
|
8
|
+
|
9
|
+
# This is not used within stimpack. Rather, this allows OTHER tools to
|
10
|
+
# hook into Stimpack via ActiveSupport hooks.
|
7
11
|
ActiveSupport.run_load_hooks(:stimpack, Packs)
|
8
12
|
end
|
9
13
|
end
|
data/lib/stimpack/version.rb
CHANGED
data/lib/stimpack.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "active_support"
|
2
|
+
require "rails/application"
|
2
3
|
|
3
4
|
module Stimpack
|
4
5
|
extend ActiveSupport::Autoload
|
@@ -14,16 +15,8 @@ module Stimpack
|
|
14
15
|
class << self
|
15
16
|
attr_reader :config
|
16
17
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
Integrations::Rails.install(app)
|
21
|
-
Integrations::FactoryBot.install(app)
|
22
|
-
Integrations::RSpec.install(app)
|
23
|
-
end
|
24
|
-
|
25
|
-
def [](name)
|
26
|
-
Packs[name.to_s]
|
18
|
+
def root
|
19
|
+
@root ||= Rails::Application.find_root(Dir.pwd)
|
27
20
|
end
|
28
21
|
end
|
29
22
|
|
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stimpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ngan Pham
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
@@ -52,6 +66,62 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: debug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sorbet
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tapioca
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
55
125
|
description: stimpack establishes and implements a set of conventions for splitting
|
56
126
|
up large monoliths.
|
57
127
|
email:
|
@@ -63,6 +133,7 @@ files:
|
|
63
133
|
- README.md
|
64
134
|
- bin/console
|
65
135
|
- bin/setup
|
136
|
+
- bin/tapioca
|
66
137
|
- lib/stimpack.rb
|
67
138
|
- lib/stimpack/integrations.rb
|
68
139
|
- lib/stimpack/integrations/factory_bot.rb
|
@@ -72,6 +143,7 @@ files:
|
|
72
143
|
- lib/stimpack/pack/configuration.rb
|
73
144
|
- lib/stimpack/packs.rb
|
74
145
|
- lib/stimpack/railtie.rb
|
146
|
+
- lib/stimpack/rspec.rb
|
75
147
|
- lib/stimpack/stim.rb
|
76
148
|
- lib/stimpack/version.rb
|
77
149
|
homepage: https://github.com/Gusto/stimpack
|
@@ -80,7 +152,7 @@ metadata:
|
|
80
152
|
homepage_uri: https://github.com/Gusto/stimpack
|
81
153
|
source_code_uri: https://github.com/Gusto/stimpack
|
82
154
|
changelog_uri: https://github.com/Gusto/stimpack/blob/master/CHANGELOG.md
|
83
|
-
post_install_message:
|
155
|
+
post_install_message:
|
84
156
|
rdoc_options: []
|
85
157
|
require_paths:
|
86
158
|
- lib
|
@@ -95,8 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
167
|
- !ruby/object:Gem::Version
|
96
168
|
version: '0'
|
97
169
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
170
|
+
rubygems_version: 3.3.7
|
171
|
+
signing_key:
|
100
172
|
specification_version: 4
|
101
173
|
summary: A Rails helper to package your code.
|
102
174
|
test_files: []
|