stimpack 0.0.1.alpha1 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbbb988cfbc8e3fb761d92e2d989dd546ef196a9acada9bae2718424c81f2d74
4
- data.tar.gz: 735f0e30435e5230f2a13d11e9bb0d46a4bfd613ff7e5af79b6bbe9c8d9ec9a8
3
+ metadata.gz: aedf6786a9c8dce60f5d90bf3f9b97bea858d3faeac218c2991a5ed5dd61503e
4
+ data.tar.gz: 1b7c218dc706f75f77d4d1e6e099f174520c26ebbf573f985f05e6e28a343af8
5
5
  SHA512:
6
- metadata.gz: 0b4e2c7457d511322225671c656267733c429fc5b4938450e466bd7fbee2a16068b5b2f4fc5ed6e33939c60d7835033b494ee6ef8407b247eda44fa2af0f04cd
7
- data.tar.gz: be22569f23c0e65833573758537e60e6fa9a67d4090f04892e44adf4705cc26b8b3e902ecd695d81d375ae823b474399ea1935f991e7d7186a1dfd4dc203ef96
6
+ metadata.gz: be4a82f48f0c966edfc9c86c096d4e8cbfe7f23177007ddd91bffe769ac7fab05921f6b7c2855b8fbadc49c54aede9024b1820f76ecbe988b492507adc3fc212
7
+ data.tar.gz: 889c48f4b28b1260e6387ba6205f5b586846630c33182f680bbbaf8bfe0a18f89529b16ef87c562991452da74bbd2191168189d1b7f4380e56448eabe586fae1
data/README.md CHANGED
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'stimpack'
12
+ gem "stimpack"
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -33,4 +33,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
33
33
  ## Contributing
34
34
 
35
35
  Bug reports and pull requests are welcome on GitHub at https://github.com/ngan/stimpack.
36
-
data/lib/stimpack.rb CHANGED
@@ -1,6 +1,58 @@
1
- require "stimpack/version"
1
+ require "active_support"
2
+ require "rails"
2
3
 
3
4
  module Stimpack
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :Integrations
8
+ autoload :Autoloaders
9
+ autoload :Packs
10
+ autoload :Settings
11
+ autoload :Stim
12
+ autoload :Railtie
13
+ autoload :Require
14
+ autoload :ZeitwerkProxy
15
+
4
16
  class Error < StandardError; end
5
- # Your code goes here...
17
+
18
+ class << self
19
+ def start!
20
+ @started = @started ? return : true
21
+
22
+ # Override Rails' autoloader accessors.
23
+ # Rails::Autoloaders.singleton_class.prepend(Autoloaders)
24
+
25
+ Packs.resolve
26
+
27
+ install_integrations
28
+ end
29
+
30
+ def finalize!
31
+ @finalized = @finalized ? return : true
32
+
33
+ Require.setup
34
+ end
35
+
36
+ def autoloader(original)
37
+ return original if @finalized
38
+
39
+ @autoloader_proxies ||= {}
40
+ @autoloader_proxies[original] ||= ZeitwerkProxy.new(original)
41
+ end
42
+
43
+ def [](name)
44
+ Packs[name.to_s]
45
+ end
46
+
47
+ private
48
+
49
+ def install_integrations
50
+ Integrations::FactoryBot.install
51
+ Integrations::RSpec.install
52
+ end
53
+ end
6
54
  end
55
+
56
+ require "stimpack/railtie"
57
+ # require "stimpack/require"
58
+ # require "stimpack/kernel"
@@ -0,0 +1,11 @@
1
+ module Stimpack
2
+ module Autoloaders
3
+ def main
4
+ Stimpack.autoloader(super)
5
+ end
6
+
7
+ def once
8
+ Stimpack.autoloader(super)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require "pathname"
2
+ require "active_support/inflector"
3
+
4
+ module Stimpack
5
+ class Instance
6
+ def initialize
7
+ Pathname.new("packages").glob("*/package.yml").each do |path|
8
+ path = path.realpath.dirname
9
+ name = ActiveSupport::Inflector.classify(path.basename)
10
+ Stimpack::Packages.create(name, path)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ require "active_support"
2
+
3
+ module Stimpack
4
+ module Integrations
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :RSpec, "stimpack/integrations/rspec"
8
+ autoload :FactoryBot, "stimpack/integrations/factory_bot"
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Stimpack
2
+ module Integrations
3
+ class FactoryBot
4
+ def self.install
5
+ return unless Rails.configuration.respond_to?(:factory_bot)
6
+
7
+ Packs.each do |pack|
8
+ Rails.configuration.factory_bot.definition_file_paths << pack.settings.relative_path.join("spec/factories").to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Stimpack
2
+ module Integrations
3
+ class RSpec
4
+ def self.install
5
+ return unless defined?(::RSpec)
6
+
7
+ Packs.each do |pack|
8
+ ::RSpec.configuration.pattern.concat(",#{pack.settings.relative_path.join("spec/**/*_spec.rb")}")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kernel
4
+ module_function
5
+
6
+ alias_method :stimpack_original_require, :require
7
+
8
+ def require(path)
9
+ stimpack_original_require(Stimpack::Require.resolve(path) || path)
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require "rails"
2
+ require "active_support/core_ext/module/delegation"
3
+
4
+ module Stimpack
5
+ class Package < ::Rails::Engine
6
+ class << self
7
+ delegate :subclasses, to: :superclass
8
+
9
+ def find_root(from)
10
+ Packages.paths[module_parent.name]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ require "rails"
2
+
3
+ module Stimpack
4
+ module Packages
5
+ def self.paths
6
+ @paths ||= {}
7
+ end
8
+
9
+ def self.create(name, path)
10
+ paths[name] = path
11
+
12
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
13
+ module ::#{name}
14
+ class Engine < ::Stimpack::Package
15
+ end
16
+ end
17
+ RUBY
18
+
19
+ engine = const_get("::#{name}::Engine")
20
+ # Isolate the package namespace.
21
+ engine.isolate_namespace(engine.module_parent)
22
+
23
+ # Disable Railtie initializers for Packages.
24
+ engine.paths["config/initializers"] = nil
25
+
26
+ engine.paths["lib/tasks"] = "tasks"
27
+ engine.paths["db/migrate"] = "migrations"
28
+ engine.paths["config/routes.rb"] = "routes.rb"
29
+
30
+ if engine.paths["db/migrate"].existent.any?
31
+ ActiveRecord::Migrator.migrations_paths << engine.paths["db/migrate"].first
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,56 @@
1
+ require "active_support"
2
+ require "pathname"
3
+ require "rails"
4
+
5
+ module Stimpack
6
+ module Packs
7
+ PATH = Pathname.new("packs").freeze
8
+ PACK_CLASS = "Pack".freeze
9
+
10
+ class << self
11
+ def resolve
12
+ PATH.glob("**/#{Settings::PACKWERK_PACKAGE_CONFIG}").each do |path|
13
+ path = path.dirname
14
+ create(path.relative_path_from(PATH).to_s, path.expand_path)
15
+ end
16
+ end
17
+
18
+ def create(name, path)
19
+ namespace = create_namespace(name)
20
+ stim = Stim.new(path)
21
+ @packs[name] = namespace.const_set(PACK_CLASS, Class.new(Rails::Engine)).include(stim)
22
+ end
23
+
24
+ def find(path)
25
+ path = "#{path}/"
26
+
27
+ @packs.values.find do |pack|
28
+ path.start_with?("#{pack.root}/")
29
+ end
30
+ end
31
+
32
+ def [](name)
33
+ @packs[name]
34
+ end
35
+
36
+ def each(*args, &block)
37
+ @packs.each_value(*args, &block)
38
+ end
39
+
40
+ private
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
+
54
+ @packs = {}
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ require "rails"
2
+
3
+ module Stimpack
4
+ class Railtie < Rails::Railtie
5
+ config.before_configuration do
6
+ Stimpack.start!
7
+ end
8
+
9
+ config.after_initialize do
10
+ Stimpack.finalize!
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stimpack
4
+ class Require
5
+ IGNORED_PATH_PREFIXES = ["/", "./"].freeze
6
+ RUBY_EXTENSION = ".rb"
7
+
8
+ include Singleton
9
+
10
+ attr_accessor :enabled
11
+
12
+ def self.resolve(path)
13
+ instance.resolve(path)
14
+ end
15
+
16
+ def self.setup
17
+ instance.setup
18
+ end
19
+
20
+ def initialize
21
+ @packs = {}
22
+ end
23
+
24
+ def setup
25
+ @setup = @setup ? return : true
26
+
27
+ Packs.each do |pack|
28
+ if pack.settings.implicit_namespace?
29
+ @packs["#{pack.settings.name}/"] = "#{pack.paths["lib"].first}/"
30
+ end
31
+ end
32
+ end
33
+
34
+ def resolve(path)
35
+ path = path.to_s
36
+ return if path.start_with?(*IGNORED_PATH_PREFIXES)
37
+
38
+ @packs.find do |pack_path, full_path|
39
+ if path.start_with?(pack_path)
40
+ full_pack_path = path.sub(pack_path, full_path)
41
+ full_pack_path.concat(RUBY_EXTENSION) unless full_pack_path.end_with?(RUBY_EXTENSION)
42
+ return File.exist?(full_pack_path) && full_pack_path
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stimpack
4
+ class Settings
5
+ PACKWERK_PACKAGE_CONFIG = "package.yml"
6
+
7
+ def initialize(pack)
8
+ @pack = pack
9
+
10
+ package_config = YAML.load_file(pack.root.join(PACKWERK_PACKAGE_CONFIG)) || {}
11
+ @config = package_config.fetch("metadata", {}).freeze
12
+ end
13
+
14
+ def path
15
+ @pack.called_from
16
+ end
17
+
18
+ def relative_path
19
+ @relative_path ||= path.relative_path_from(Rails.root)
20
+ end
21
+
22
+ def name
23
+ @name ||= ActiveSupport::Inflector.underscore(namespace.name)
24
+ end
25
+
26
+ def namespace
27
+ @pack.module_parent
28
+ end
29
+
30
+ # def implicit_namespace
31
+ # @config.fetch("implicit_namespace", true)
32
+ # end
33
+ # alias_method :implicit_namespace?, :implicit_namespace
34
+
35
+ def isolate_namespace
36
+ @config.fetch("isolate_namespace", true)
37
+ end
38
+ alias_method :isolate_namespace?, :isolate_namespace
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ module Stimpack
2
+ class Stim < Module
3
+ def initialize(path)
4
+ @path = path
5
+ super()
6
+ end
7
+
8
+ def included(engine)
9
+ engine.called_from = @path
10
+ engine.extend(ClassMethods)
11
+ settings = engine.settings
12
+
13
+ if settings.isolate_namespace?
14
+ engine.isolate_namespace(settings.namespace)
15
+ end
16
+
17
+ # if settings.implicit_namespace?
18
+ # engine.paths["lib"].skip_load_path!
19
+ # end
20
+ end
21
+
22
+ module ClassMethods
23
+ def find_root(_from)
24
+ called_from
25
+ end
26
+
27
+ def settings
28
+ @settings ||= Stimpack::Settings.new(self)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Stimpack
2
- VERSION = "0.0.1.alpha1"
2
+ VERSION = "1.0.0.alpha1".freeze
3
3
  end
@@ -0,0 +1,24 @@
1
+ require "active_support"
2
+
3
+ module Stimpack
4
+ class ZeitwerkProxy
5
+ delegate_missing_to :@loader
6
+
7
+ def initialize(loader)
8
+ @loader = loader
9
+ end
10
+
11
+ def push_dir(path, namespace: Object)
12
+ @loader.push_dir(path, namespace: _resolve_namespace(path) || namespace)
13
+ end
14
+
15
+ private
16
+
17
+ def _resolve_namespace(path)
18
+ pack = Packs.find(path)
19
+ return unless pack
20
+
21
+ pack.settings.namespace if pack.settings.implicit_namespace?
22
+ end
23
+ end
24
+ end
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.1.alpha1
4
+ version: 1.0.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Name hold for upcoming gem
11
+ date: 2021-02-20 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,7 +63,21 @@ files:
21
63
  - bin/console
22
64
  - bin/setup
23
65
  - lib/stimpack.rb
66
+ - lib/stimpack/autoloaders.rb
67
+ - lib/stimpack/instance.rb
68
+ - lib/stimpack/integrations.rb
69
+ - lib/stimpack/integrations/factory_bot.rb
70
+ - lib/stimpack/integrations/rspec.rb
71
+ - lib/stimpack/kernel.rb
72
+ - lib/stimpack/package.rb
73
+ - lib/stimpack/packages.rb
74
+ - lib/stimpack/packs.rb
75
+ - lib/stimpack/railtie.rb
76
+ - lib/stimpack/require.rb
77
+ - lib/stimpack/settings.rb
78
+ - lib/stimpack/stim.rb
24
79
  - lib/stimpack/version.rb
80
+ - lib/stimpack/zeitwerk_proxy.rb
25
81
  homepage: https://github.com/Gusto/stimpack
26
82
  licenses: []
27
83
  metadata:
@@ -36,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
92
  requirements:
37
93
  - - ">="
38
94
  - !ruby/object:Gem::Version
39
- version: 2.3.0
95
+ version: '2.7'
40
96
  required_rubygems_version: !ruby/object:Gem::Requirement
41
97
  requirements:
42
98
  - - ">"
@@ -46,5 +102,5 @@ requirements: []
46
102
  rubygems_version: 3.1.2
47
103
  signing_key:
48
104
  specification_version: 4
49
- summary: Name hold for upcoming gem
105
+ summary: A Rails helper to package your code.
50
106
  test_files: []