stimpack 0.0.1.alpha1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +25 -0
- data/lib/stimpack/pack.rb +47 -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: 77c100a2db422cb489d3405605ad303d16f83881a5a7fc041217e424672ce6fa
|
4
|
+
data.tar.gz: 3bb479b3ff75547dc957609dad9b9bb109a3e6396f220d5f0bf04056d5ea8fb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '059c1b11d33c8d26d3c08deff15d2864cba2484fae0d62e33042d6feb88a9f40a869522f93847b5bcdb4d654eebf6f1337979e288ad5bce047e104aa83718d21'
|
7
|
+
data.tar.gz: 42bab45829e429e543e898cdece963e185e53adbc692611f5ddaacaafcccd4e03376cd4cba1a3dc8f6872d66808127fa8d8c05d49e911e3181eef7abe2d32707
|
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,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stimpack
|
4
|
+
class Pack
|
5
|
+
class Configuration
|
6
|
+
FILE = "package.yml"
|
7
|
+
KEY = "metadata"
|
8
|
+
|
9
|
+
def initialize(pack)
|
10
|
+
@pack = pack
|
11
|
+
end
|
12
|
+
|
13
|
+
def engine
|
14
|
+
data.fetch("engine", false)
|
15
|
+
end
|
16
|
+
alias_method :engine?, :engine
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def data
|
21
|
+
@data ||= YAML.load_file(@pack.path.join(FILE)).fetch(KEY, {}).freeze
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stimpack
|
4
|
+
class Pack
|
5
|
+
autoload :Configuration, "stimpack/pack/configuration"
|
6
|
+
|
7
|
+
attr_reader :name
|
8
|
+
attr_reader :path
|
9
|
+
attr_reader :engine
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@path = path
|
13
|
+
@name = path.relative_path_from(Packs.root)
|
14
|
+
|
15
|
+
if config.engine?
|
16
|
+
@engine = create_engine
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def relative_path
|
21
|
+
@relative_path ||= path.relative_path_from(Rails.root)
|
22
|
+
end
|
23
|
+
|
24
|
+
def config
|
25
|
+
@config ||= Configuration.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def create_engine
|
31
|
+
namespace = create_namespace(name)
|
32
|
+
stim = Stim.new(self, namespace)
|
33
|
+
namespace.const_set("Engine", Class.new(Rails::Engine)).include(stim)
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_namespace(name)
|
37
|
+
namespace = ActiveSupport::Inflector.camelize(name)
|
38
|
+
namespace.split("::").reduce(Object) do |base, mod|
|
39
|
+
if base.const_defined?(mod)
|
40
|
+
base.const_get(mod)
|
41
|
+
else
|
42
|
+
base.const_set(mod, Module.new)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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
|
+
pack = Pack.new(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.
|
4
|
+
version: 0.1.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-07 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: []
|