stimpack 0.7.1 → 0.8.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 +25 -2
- data/lib/stimpack/integrations/factory_bot.rb +2 -0
- data/lib/stimpack/integrations/rails.rb +10 -5
- data/lib/stimpack/integrations/rspec.rb +14 -2
- data/lib/stimpack/stim.rb +7 -2
- data/lib/stimpack/version.rb +1 -1
- data/lib/stimpack.rb +4 -3
- metadata +17 -6
- data/lib/stimpack/pack/configuration.rb +0 -30
- data/lib/stimpack/pack.rb +0 -28
- data/lib/stimpack/packs.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46d22ca966c49e9a2f424291c0c44caec1ea24664c3239f1cca1fa4e218e91bf
|
4
|
+
data.tar.gz: 5a393fa3f27d5b9bcab1edf0d193f9a4cf7d64410d4184725b6cc26ac6e66679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ab5bfa795b0cd6008a13df1bb297e51191b5da2e561421e64b1fef71a80724709ffed50fdb66504102ca4625d532afb77564744564b8f77919c2aa3ff68b1b
|
7
|
+
data.tar.gz: 70eb5b61e2739cd657f31bd0ec79bc221f12ac3c0507365fec6701fda7deaae4839d0c127c6bab423ac3083b35852e03d0b5b0e4fd042245c894e45e48dce166
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ packs/
|
|
46
46
|
my_domain/
|
47
47
|
my_private_namespaced_model_factory.rb
|
48
48
|
my_other_domain/
|
49
|
-
... # other
|
49
|
+
... # other packs have a similar structure
|
50
50
|
my_other_other_domain/
|
51
51
|
...
|
52
52
|
```
|
@@ -83,7 +83,7 @@ draw(:my_domain)
|
|
83
83
|
```
|
84
84
|
|
85
85
|
### Making your Package an Engine
|
86
|
-
Add `engine: true` to your `package.yml` to make it an actual Rails engine:
|
86
|
+
Add `engine: true` to your `package.yml` to make it an actual Rails engine ([read more about what this means here](https://guides.rubyonrails.org/engines.html)):
|
87
87
|
```yml
|
88
88
|
# packs/my_pack/package.yml
|
89
89
|
enforce_dependencies: true
|
@@ -92,6 +92,8 @@ metadata:
|
|
92
92
|
engine: true
|
93
93
|
```
|
94
94
|
|
95
|
+
## Ecosystem and Integrations
|
96
|
+
|
95
97
|
### RSpec Integration
|
96
98
|
Simply add `--require stimpack/rspec` to your `.rspec`.
|
97
99
|
Or, if you'd like, pass it as an argument to `rspec`:
|
@@ -121,6 +123,27 @@ rspec packs/foobar/spec
|
|
121
123
|
rspec packs/foobar/nested_pack
|
122
124
|
```
|
123
125
|
|
126
|
+
#### parallel_tests
|
127
|
+
|
128
|
+
`parallel_tests` has it its own spec discovery mechanism, so Stimpack's RSpec integration doesn't do anything when you use them together.
|
129
|
+
To make them work, you'll need to explicitly specify the spec paths:
|
130
|
+
|
131
|
+
```bash
|
132
|
+
RAILS_ENV=test bundle exec parallel_test spec packs/**/spec -t rspec <other_options>
|
133
|
+
```
|
134
|
+
|
135
|
+
#### Knapsack (Pro)
|
136
|
+
|
137
|
+
Similarly, Knapsack (and its Pro version) has its own spec discovery mechanism and the API will find and queue the relevant specs.
|
138
|
+
To make it discover your pack tests as well, you'll need to configure the following variables:
|
139
|
+
|
140
|
+
```yaml
|
141
|
+
KNAPSACK_PRO_TEST_DIR: spec
|
142
|
+
KNAPSACK_PRO_TEST_FILE_PATTERN: '{spec,packs}/**{,/*/**}/*_spec.rb'
|
143
|
+
```
|
144
|
+
|
145
|
+
Setting `KNAPSACK_PRO_TEST_FILE_PATTERN` will tell Knapsack where your specs are located, while setting `KNAPSACK_PRO_TEST_DIR` is necessary because otherwise an incorrect value is sent to rspec via the `--default-path` option.
|
146
|
+
|
124
147
|
## Contributing
|
125
148
|
|
126
149
|
Bug reports and pull requests are welcome on GitHub at https://github.com/Gusto/stimpack.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: true
|
2
3
|
|
3
4
|
require "active_support/inflections"
|
4
5
|
|
@@ -14,17 +15,21 @@ module Stimpack
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def create_engines
|
18
|
+
# Ideally, the user just does `Packs.configure { |config| config.roots = '...' }`
|
19
|
+
# But that would be a public API change and can come later
|
20
|
+
Packs.configure { |config| config.roots = Array(Stimpack.config.root) }
|
21
|
+
|
17
22
|
Packs.all.each do |pack|
|
18
|
-
next unless pack.
|
23
|
+
next unless pack.metadata['engine']
|
19
24
|
|
20
|
-
|
25
|
+
create_engine(pack)
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def inject_paths
|
25
30
|
Packs.all.each do |pack|
|
26
31
|
Stimpack.config.paths.each do |path|
|
27
|
-
@app.paths[path] << pack.
|
32
|
+
@app.paths[path] << pack.relative_path.join(path)
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
@@ -43,8 +48,8 @@ module Stimpack
|
|
43
48
|
end
|
44
49
|
|
45
50
|
def create_engine(pack)
|
46
|
-
name = pack.
|
47
|
-
namespace = create_namespace(
|
51
|
+
name = pack.last_name
|
52
|
+
namespace = create_namespace(name)
|
48
53
|
stim = Stim.new(pack, namespace)
|
49
54
|
namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
|
50
55
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Stimpack
|
2
4
|
module Integrations
|
3
5
|
class RSpec
|
6
|
+
extend T::Sig
|
7
|
+
|
4
8
|
def initialize
|
5
9
|
# This is the list of directories RSpec was told to run.
|
6
10
|
to_run = ::RSpec.configuration.instance_variable_get(:@files_or_directories_to_run)
|
@@ -10,6 +14,7 @@ module Stimpack
|
|
10
14
|
# This is the default case when you run `rspec`. We want to add all the pack's spec paths
|
11
15
|
# to the collection of directories to run.
|
12
16
|
|
17
|
+
Packs.configure { |config| config.roots = Array(Stimpack.config.root) }
|
13
18
|
pack_paths = Packs.all.map do |pack|
|
14
19
|
spec_path = pack.relative_path.join(default_path)
|
15
20
|
spec_path.to_s if spec_path.exist?
|
@@ -26,10 +31,10 @@ module Stimpack
|
|
26
31
|
# If it doesn't match a pack path, we leave it alone.
|
27
32
|
|
28
33
|
to_run.map! do |path|
|
29
|
-
if pack = Packs.
|
34
|
+
if pack = Packs.find(path)
|
30
35
|
[
|
31
36
|
pack,
|
32
|
-
*
|
37
|
+
*nested_packs_for(pack)
|
33
38
|
].map do |pack|
|
34
39
|
spec_path = pack.relative_path.join(default_path)
|
35
40
|
spec_path.to_s if spec_path.exist?
|
@@ -42,6 +47,13 @@ module Stimpack
|
|
42
47
|
|
43
48
|
::RSpec.configuration.files_or_directories_to_run = to_run.flatten.compact.uniq
|
44
49
|
end
|
50
|
+
|
51
|
+
sig { params(parent_pack: Packs::Pack).returns(T::Array[Packs::Pack]) }
|
52
|
+
def nested_packs_for(parent_pack)
|
53
|
+
Packs.all.select do |pack|
|
54
|
+
pack.name != parent_pack.name && pack.name.include?(parent_pack.name)
|
55
|
+
end
|
56
|
+
end
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
data/lib/stimpack/stim.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
module Stimpack
|
2
4
|
class Stim < Module
|
5
|
+
extend T::Sig
|
6
|
+
|
7
|
+
sig { params(pack: Packs::Pack, namespace: Module).void }
|
3
8
|
def initialize(pack, namespace)
|
4
9
|
@pack = pack
|
5
10
|
@namespace = namespace
|
@@ -7,7 +12,7 @@ module Stimpack
|
|
7
12
|
end
|
8
13
|
|
9
14
|
def included(engine)
|
10
|
-
engine.called_from = @pack.
|
15
|
+
engine.called_from = @pack.relative_path
|
11
16
|
engine.extend(ClassMethods)
|
12
17
|
engine.isolate_namespace(@namespace)
|
13
18
|
|
@@ -28,7 +33,7 @@ module Stimpack
|
|
28
33
|
|
29
34
|
module ClassMethods
|
30
35
|
def find_root(_from)
|
31
|
-
called_from
|
36
|
+
T.unsafe(self).called_from
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
data/lib/stimpack/version.rb
CHANGED
data/lib/stimpack.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
require 'packs'
|
1
2
|
require "active_support"
|
2
3
|
require "rails/application"
|
4
|
+
require 'sorbet-runtime'
|
3
5
|
|
4
6
|
module Stimpack
|
5
7
|
extend ActiveSupport::Autoload
|
6
8
|
|
7
9
|
autoload :Integrations
|
8
|
-
autoload :Pack
|
9
|
-
autoload :Packs
|
10
10
|
autoload :Railtie
|
11
11
|
autoload :Stim
|
12
12
|
|
@@ -21,7 +21,8 @@ module Stimpack
|
|
21
21
|
end
|
22
22
|
|
23
23
|
@config = ActiveSupport::OrderedOptions.new
|
24
|
-
|
24
|
+
# Should this allow a plural version to be set? What are semantics of that?
|
25
|
+
@config.root = Array("packs".freeze)
|
25
26
|
@config.paths = %w(
|
26
27
|
app
|
27
28
|
app/controllers
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stimpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ngan Pham
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: packs
|
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: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,9 +153,6 @@ files:
|
|
139
153
|
- lib/stimpack/integrations/factory_bot.rb
|
140
154
|
- lib/stimpack/integrations/rails.rb
|
141
155
|
- lib/stimpack/integrations/rspec.rb
|
142
|
-
- lib/stimpack/pack.rb
|
143
|
-
- lib/stimpack/pack/configuration.rb
|
144
|
-
- lib/stimpack/packs.rb
|
145
156
|
- lib/stimpack/railtie.rb
|
146
157
|
- lib/stimpack/rspec.rb
|
147
158
|
- lib/stimpack/stim.rb
|
@@ -167,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
178
|
- !ruby/object:Gem::Version
|
168
179
|
version: '0'
|
169
180
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
181
|
+
rubygems_version: 3.1.6
|
171
182
|
signing_key:
|
172
183
|
specification_version: 4
|
173
184
|
summary: A Rails helper to package your code.
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
module Stimpack
|
6
|
-
class Pack
|
7
|
-
class Configuration
|
8
|
-
KEY = "metadata"
|
9
|
-
|
10
|
-
def initialize(path)
|
11
|
-
@path = path
|
12
|
-
end
|
13
|
-
|
14
|
-
def engine
|
15
|
-
data.fetch("engine", false)
|
16
|
-
end
|
17
|
-
alias_method :engine?, :engine
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def 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
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/stimpack/pack.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "pathname"
|
4
|
-
|
5
|
-
module Stimpack
|
6
|
-
class Pack
|
7
|
-
PACKAGE_FILE = "package.yml"
|
8
|
-
|
9
|
-
autoload :Configuration, "stimpack/pack/configuration"
|
10
|
-
|
11
|
-
attr_reader :path
|
12
|
-
attr_reader :name
|
13
|
-
attr_accessor :engine
|
14
|
-
|
15
|
-
def initialize(path)
|
16
|
-
@path = path
|
17
|
-
@name = path.basename.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
def relative_path
|
21
|
-
@relative_path ||= path.relative_path_from(Stimpack.root)
|
22
|
-
end
|
23
|
-
|
24
|
-
def config
|
25
|
-
@config ||= Configuration.new(path.join(PACKAGE_FILE))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/stimpack/packs.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_support"
|
4
|
-
|
5
|
-
module Stimpack
|
6
|
-
module Packs
|
7
|
-
PACKAGE_GLOB_PATTERN = "*/#{Pack::PACKAGE_FILE}"
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def root
|
11
|
-
@root ||= Stimpack.root.join(Stimpack.config.root)
|
12
|
-
end
|
13
|
-
|
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
|
-
end
|
20
|
-
end
|
21
|
-
|
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
|
26
|
-
|
27
|
-
if parent
|
28
|
-
@all[parent]
|
29
|
-
else
|
30
|
-
@all.keys + @all.values.flatten
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
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
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def resolve(directory)
|
43
|
-
directory.glob(PACKAGE_GLOB_PATTERN).map { |path| Pack.new(path.dirname) }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|