stimpack 0.0.1.alpha1 → 0.3.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 +73 -23
- data/lib/stimpack/integrations/factory_bot.rb +13 -0
- data/lib/stimpack/integrations/rails.rb +17 -0
- data/lib/stimpack/integrations/rspec.rb +13 -0
- data/lib/stimpack/integrations.rb +9 -0
- data/lib/stimpack/pack/configuration.rb +24 -0
- data/lib/stimpack/pack.rb +53 -0
- data/lib/stimpack/packs.rb +42 -0
- data/lib/stimpack/railtie.rb +10 -0
- data/lib/stimpack/stim.rb +35 -0
- data/lib/stimpack/version.rb +1 -1
- data/lib/stimpack.rb +44 -2
- metadata +63 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a182ce65cfc7f331c0b8aab98cb9f66f74e24b2892f07759b6fc0663d2ed9d2
|
4
|
+
data.tar.gz: cfbdf8284d0b3c054c2708bd69bfc0eb63341044e93ca064cf9971b17e391a06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dfc2c8a19b50159cddb6f5ace4a593e8f69d8719ee607c3994fed1b1541cfb639fa1bba1bb458eff632487cf65e84181899bd3c3343192ddd5f03abd6f8bd7a
|
7
|
+
data.tar.gz: 1c7f5dce375f55b6733ac771d86f3799aa408335e0d17b11cff6c9e7d47e7ff6d53ccd54c5f944419bad9a9eda2a0c2146c4048dcf26ff643e056119302fb66c
|
data/README.md
CHANGED
@@ -1,36 +1,86 @@
|
|
1
1
|
# Stimpack
|
2
2
|
|
3
|
-
|
3
|
+
`stimpack` makes integrating with [`packwerk`](https://github.com/Shopify/packwerk) easy and establishes conventions such that packwerk packages mimic the feel and structure of [Rails engines](https://guides.rubyonrails.org/engines.html), without all of the boilerplate. With `stimpack`, new packages' autoload paths are automatically added to Rails, so your code will immediately become usable and loadable without additional configuration.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
Here is an example application that uses `stimpack`:
|
6
|
+
```
|
7
|
+
package.yml # root level pack
|
8
|
+
app/ # Unpackaged code
|
9
|
+
models/
|
10
|
+
...
|
11
|
+
packs/
|
12
|
+
my_domain/
|
13
|
+
package.yml # See the packwerk docs for more info
|
14
|
+
deprecated_references.yml # See the packwerk docs for more info
|
15
|
+
app/
|
16
|
+
public/ # Recommended location for public API
|
17
|
+
my_domain.rb # creates the primary namespaces
|
18
|
+
my_domain/
|
19
|
+
my_subdomain.rb
|
20
|
+
services/ # Private services
|
21
|
+
my_domain/
|
22
|
+
some_private_class.rb
|
23
|
+
models/ # Private models
|
24
|
+
some_other_non_namespaced_private_model.rb # this works too
|
25
|
+
my_domain/
|
26
|
+
my_private_namespacd_model.rb
|
27
|
+
config/
|
28
|
+
initializers/ # Initializers can live in packs and load as expected
|
29
|
+
controllers/
|
30
|
+
views/
|
31
|
+
lib/
|
32
|
+
tasks/
|
33
|
+
spec/ # With stimpack, specs for a pack live next to the pack
|
34
|
+
public/
|
35
|
+
my_domain_spec.rb
|
36
|
+
my_domain/
|
37
|
+
my_subdomain_spec.rb
|
38
|
+
services/
|
39
|
+
my_domain/
|
40
|
+
some_private_class_spec.rb
|
41
|
+
models/
|
42
|
+
some_other_non_namespaced_private_model_spec.rb
|
43
|
+
my_domain/
|
44
|
+
my_private_namespaced_model_spec.rb
|
45
|
+
factories/ # Stimpack will automatically load pack factories into FactoryBot
|
46
|
+
my_domain/
|
47
|
+
my_private_namespaced_model_factory.rb
|
48
|
+
my_other_domain/
|
49
|
+
... # other pack's have a similar structure
|
50
|
+
my_other_other_domain/
|
51
|
+
...
|
13
52
|
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install stimpack
|
22
53
|
|
23
54
|
## Usage
|
24
55
|
|
25
|
-
|
56
|
+
Setting up `stimpack` is straightforward. Simply by including `stimpack` in your `Gemfile` in all environments, `stimpack` will automatically hook into and configure Rails.
|
26
57
|
|
27
|
-
|
58
|
+
From there, you can create a `./packs` folder and structure it using the conventions listed above.
|
28
59
|
|
29
|
-
|
60
|
+
If you wish to use a different directory name, eg `components` instead of `packs`, you can customize this in your `config/application.rb` file:
|
30
61
|
|
31
|
-
|
62
|
+
```ruby
|
63
|
+
# Customize Stimpack's root directory. Note that this has to be done _before_ the Application
|
64
|
+
# class is declared.
|
65
|
+
Stimpack.config.root = "components"
|
66
|
+
|
67
|
+
module MyCoolApp
|
68
|
+
class Application < Rails::Application
|
69
|
+
# ...
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
32
73
|
|
33
|
-
|
74
|
+
### Making your Package an Engine
|
75
|
+
Add `engine: true` to your `package.yml` to make it an actual Rails engine:
|
76
|
+
```yml
|
77
|
+
# packs/my_pack/package.yml
|
78
|
+
enforce_dependencies: true
|
79
|
+
enforce_privacy: true
|
80
|
+
metadata:
|
81
|
+
engine: true
|
82
|
+
```
|
34
83
|
|
35
|
-
|
84
|
+
## Contributing
|
36
85
|
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Gusto/stimpack.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Stimpack
|
2
|
+
module Integrations
|
3
|
+
class FactoryBot
|
4
|
+
def self.install(app)
|
5
|
+
return unless app.config.respond_to?(:factory_bot)
|
6
|
+
|
7
|
+
Packs.each do |pack|
|
8
|
+
app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stimpack
|
4
|
+
module Integrations
|
5
|
+
class Rails
|
6
|
+
def self.install(app)
|
7
|
+
Stimpack.config.paths.freeze
|
8
|
+
|
9
|
+
Packs.each do |pack|
|
10
|
+
Stimpack.config.paths.each do |path|
|
11
|
+
app.paths[path] << pack.path.join(path)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Stimpack
|
2
|
+
module Integrations
|
3
|
+
class RSpec
|
4
|
+
def self.install(app)
|
5
|
+
return unless defined?(::RSpec)
|
6
|
+
|
7
|
+
Packs.each do |pack|
|
8
|
+
::RSpec.configuration.pattern.concat(",#{pack.relative_path.join("spec/**/*_spec.rb")}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stimpack
|
4
|
+
class Pack
|
5
|
+
class Configuration
|
6
|
+
KEY = "metadata"
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def engine
|
13
|
+
data.fetch("engine", false)
|
14
|
+
end
|
15
|
+
alias_method :engine?, :engine
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def data
|
20
|
+
@data ||= YAML.load_file(@path).fetch(KEY, {}).freeze
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stimpack
|
4
|
+
class Pack
|
5
|
+
PACKAGE_FILE = "package.yml"
|
6
|
+
|
7
|
+
autoload :Configuration, "stimpack/pack/configuration"
|
8
|
+
|
9
|
+
attr_reader :name
|
10
|
+
attr_reader :path
|
11
|
+
attr_reader :engine
|
12
|
+
|
13
|
+
def self.create(path)
|
14
|
+
new(path) if path.join(PACKAGE_FILE).exist?
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(path)
|
18
|
+
@path = path
|
19
|
+
@name = path.relative_path_from(Packs.root)
|
20
|
+
|
21
|
+
if config.engine?
|
22
|
+
@engine = create_engine
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def relative_path
|
27
|
+
@relative_path ||= path.relative_path_from(Rails.root)
|
28
|
+
end
|
29
|
+
|
30
|
+
def config
|
31
|
+
@config ||= Configuration.new(path.join(PACKAGE_FILE))
|
32
|
+
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
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "pathname"
|
5
|
+
require "rails"
|
6
|
+
|
7
|
+
module Stimpack
|
8
|
+
module Packs
|
9
|
+
class << self
|
10
|
+
def root
|
11
|
+
@root ||= Rails.root.join(Stimpack.config.root)
|
12
|
+
end
|
13
|
+
|
14
|
+
def resolve
|
15
|
+
# Gather all the packs under the root directory and create packs.
|
16
|
+
root.children.select(&:directory?).sort!.each do |path|
|
17
|
+
next unless pack = Pack.create(path)
|
18
|
+
@packs[pack.name] = pack
|
19
|
+
end
|
20
|
+
@packs.freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(path)
|
24
|
+
path = "#{path}/"
|
25
|
+
|
26
|
+
@packs.values.find do |pack|
|
27
|
+
path.start_with?("#{pack.path}/")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](name)
|
32
|
+
@packs[name]
|
33
|
+
end
|
34
|
+
|
35
|
+
def each(*args, &block)
|
36
|
+
@packs.each_value(*args, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@packs = {}
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Stimpack
|
2
|
+
class Stim < Module
|
3
|
+
def initialize(pack, namespace)
|
4
|
+
@pack = pack
|
5
|
+
@namespace = namespace
|
6
|
+
super()
|
7
|
+
end
|
8
|
+
|
9
|
+
def included(engine)
|
10
|
+
engine.called_from = @pack.path
|
11
|
+
engine.extend(ClassMethods)
|
12
|
+
engine.isolate_namespace(@namespace)
|
13
|
+
|
14
|
+
# Set all of these paths to nil because we want the Rails integration to take
|
15
|
+
# care of them. The purpose of this Engine is really just for the namespace
|
16
|
+
# isolation.
|
17
|
+
(Stimpack.config.paths +
|
18
|
+
# In addition to the paths we've delegated to the main app, we don't allow
|
19
|
+
# Engine Packs to have various capabilities.
|
20
|
+
%w(
|
21
|
+
config/environments
|
22
|
+
db/migrate
|
23
|
+
)
|
24
|
+
).uniq.each do |path|
|
25
|
+
engine.paths[path] = nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
def find_root(_from)
|
31
|
+
called_from
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/stimpack/version.rb
CHANGED
data/lib/stimpack.rb
CHANGED
@@ -1,6 +1,48 @@
|
|
1
|
-
require "
|
1
|
+
require "active_support"
|
2
2
|
|
3
3
|
module Stimpack
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
|
6
|
+
autoload :Integrations
|
7
|
+
autoload :Pack
|
8
|
+
autoload :Packs
|
9
|
+
autoload :Railtie
|
10
|
+
autoload :Stim
|
11
|
+
|
4
12
|
class Error < StandardError; end
|
5
|
-
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_reader :config
|
16
|
+
|
17
|
+
def load(app)
|
18
|
+
Packs.resolve
|
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]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@config = ActiveSupport::OrderedOptions.new
|
31
|
+
@config.root = "packs".freeze
|
32
|
+
@config.paths = %w(
|
33
|
+
app
|
34
|
+
app/controllers
|
35
|
+
app/channels
|
36
|
+
app/helpers
|
37
|
+
app/models
|
38
|
+
app/mailers
|
39
|
+
app/views
|
40
|
+
lib
|
41
|
+
lib/tasks
|
42
|
+
config
|
43
|
+
config/locales
|
44
|
+
config/initializers
|
45
|
+
)
|
6
46
|
end
|
47
|
+
|
48
|
+
require "stimpack/railtie"
|
metadata
CHANGED
@@ -1,16 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stimpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.3.0
|
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:
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2022-03-08 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: '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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Package your code.
|
14
56
|
email:
|
15
57
|
- gusto-opensource-buildkite@gusto.com
|
16
58
|
executables: []
|
@@ -21,6 +63,15 @@ files:
|
|
21
63
|
- bin/console
|
22
64
|
- bin/setup
|
23
65
|
- lib/stimpack.rb
|
66
|
+
- lib/stimpack/integrations.rb
|
67
|
+
- lib/stimpack/integrations/factory_bot.rb
|
68
|
+
- lib/stimpack/integrations/rails.rb
|
69
|
+
- lib/stimpack/integrations/rspec.rb
|
70
|
+
- lib/stimpack/pack.rb
|
71
|
+
- lib/stimpack/pack/configuration.rb
|
72
|
+
- lib/stimpack/packs.rb
|
73
|
+
- lib/stimpack/railtie.rb
|
74
|
+
- lib/stimpack/stim.rb
|
24
75
|
- lib/stimpack/version.rb
|
25
76
|
homepage: https://github.com/Gusto/stimpack
|
26
77
|
licenses: []
|
@@ -28,7 +79,7 @@ metadata:
|
|
28
79
|
homepage_uri: https://github.com/Gusto/stimpack
|
29
80
|
source_code_uri: https://github.com/Gusto/stimpack
|
30
81
|
changelog_uri: https://github.com/Gusto/stimpack/blob/master/CHANGELOG.md
|
31
|
-
post_install_message:
|
82
|
+
post_install_message:
|
32
83
|
rdoc_options: []
|
33
84
|
require_paths:
|
34
85
|
- lib
|
@@ -36,15 +87,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
87
|
requirements:
|
37
88
|
- - ">="
|
38
89
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
90
|
+
version: '2.7'
|
40
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
92
|
requirements:
|
42
|
-
- - "
|
93
|
+
- - ">="
|
43
94
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
95
|
+
version: '0'
|
45
96
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
97
|
+
rubygems_version: 3.2.32
|
98
|
+
signing_key:
|
48
99
|
specification_version: 4
|
49
|
-
summary:
|
100
|
+
summary: A Rails helper to package your code.
|
50
101
|
test_files: []
|