stimpack 1.0.0.alpha5 → 1.0.0.alpha6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21ba1439fa4a748325f454945071ef783c608ca679abcf6756300976afed414a
4
- data.tar.gz: 4ca99c4daac00bb7c4c44e9c8f9a32e59019201dd3d84ca3717cdcaccb253103
3
+ metadata.gz: f7e4f58a5817580fd238b6a209d51565f992d7c39ade6003338d168c2a52235b
4
+ data.tar.gz: 372c732e00ab4fb1c301e8c44ff483954c8fd9864166712e9a42dff124d9bfb8
5
5
  SHA512:
6
- metadata.gz: 88dfe424e0df8beea1894aec9c1d67a7e5b4134464ab9162650fbf592e1d07afb3aa8fb81b355f900bb36614be6ae3048b1ac44675736b35dc18eda02cad01a9
7
- data.tar.gz: d4d72de149d1f9ec3321e71e9c6980b9841535e1b737dd9979b3c68667306e5b531a88aa3f7ceffe4f8484ef1f43f32954448aa3f5c5f1528f55eef11548dcfe
6
+ metadata.gz: 03fbcedb9c236fe384c124a7ca8f923a1717862d648f134a5954960136b33e2297b2c803e7335af22fe0cc8212e8420cdac1131618c5abfdb353975550e96c3c
7
+ data.tar.gz: 107de7c60b5dc14f02196bc04df5ea933122038a0fae17fac9a144ecfc9b0e22a3ede60cd28699061475771bcc056bf3c26b9df7620b47b7a2d54022e9c28f8d
data/lib/stimpack.rb CHANGED
@@ -5,36 +5,25 @@ module Stimpack
5
5
  extend ActiveSupport::Autoload
6
6
 
7
7
  autoload :Integrations
8
+ autoload :Pack
8
9
  autoload :Packs
9
10
  autoload :Railtie
10
- autoload :Settings
11
11
  autoload :Stim
12
12
 
13
13
  class Error < StandardError; end
14
14
 
15
15
  class << self
16
- def start!
17
- @started = @started ? return : true
18
-
16
+ def load(app)
19
17
  Packs.resolve
20
18
 
21
- install_integrations
22
- end
23
-
24
- def finalize!
25
- @finalized = @finalized ? return : true
19
+ Integrations::Rails.install(app)
20
+ Integrations::FactoryBot.install(app)
21
+ Integrations::RSpec.install(app)
26
22
  end
27
23
 
28
24
  def [](name)
29
25
  Packs[name.to_s]
30
26
  end
31
-
32
- private
33
-
34
- def install_integrations
35
- Integrations::FactoryBot.install
36
- Integrations::RSpec.install
37
- end
38
27
  end
39
28
  end
40
29
 
@@ -2,9 +2,8 @@ require "active_support"
2
2
 
3
3
  module Stimpack
4
4
  module Integrations
5
- extend ActiveSupport::Autoload
6
-
7
- autoload :RSpec, "stimpack/integrations/rspec"
8
5
  autoload :FactoryBot, "stimpack/integrations/factory_bot"
6
+ autoload :Rails, "stimpack/integrations/rails"
7
+ autoload :RSpec, "stimpack/integrations/rspec"
9
8
  end
10
9
  end
@@ -1,11 +1,11 @@
1
1
  module Stimpack
2
2
  module Integrations
3
3
  class FactoryBot
4
- def self.install
5
- return unless Rails.configuration.respond_to?(:factory_bot)
4
+ def self.install(app)
5
+ return unless app.config.respond_to?(:factory_bot)
6
6
 
7
7
  Packs.each do |pack|
8
- Rails.configuration.factory_bot.definition_file_paths << pack.settings.relative_path.join("spec/factories").to_s
8
+ app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stimpack
4
+ module Integrations
5
+ class Rails
6
+ PATHS = %w(
7
+ app
8
+ app/controllers
9
+ app/channels
10
+ app/helpers
11
+ app/models
12
+ app/mailers
13
+ app/views
14
+ lib
15
+ lib/tasks
16
+ config
17
+ config/locales
18
+ config/initializers
19
+ ).freeze
20
+
21
+ def self.install(app)
22
+ Packs.each do |pack|
23
+ PATHS.each do |path|
24
+ app.paths[path] << pack.path.join(path)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,11 +1,11 @@
1
1
  module Stimpack
2
2
  module Integrations
3
3
  class RSpec
4
- def self.install
4
+ def self.install(app)
5
5
  return unless defined?(::RSpec)
6
6
 
7
7
  Packs.each do |pack|
8
- ::RSpec.configuration.pattern.concat(",#{pack.settings.relative_path.join("spec/**/*_spec.rb")}")
8
+ ::RSpec.configuration.pattern.concat(",#{pack.relative_path.join("spec/**/*_spec.rb")}")
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,51 @@
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 self.root
12
+ @root ||= Rails.root.join("packs")
13
+ end
14
+
15
+ def initialize(path)
16
+ @path = path
17
+ @name = path.relative_path_from(self.class.root)
18
+
19
+ if config.engine?
20
+ @engine = create_engine
21
+ end
22
+ end
23
+
24
+ def relative_path
25
+ @relative_path ||= path.relative_path_from(Rails.root)
26
+ end
27
+
28
+ def config
29
+ @config ||= Configuration.new(self)
30
+ end
31
+
32
+ private
33
+
34
+ def create_engine
35
+ namespace = create_namespace(name)
36
+ stim = Stim.new(self, namespace)
37
+ namespace.const_set("Engine", Class.new(Rails::Engine)).include(stim)
38
+ end
39
+
40
+ def create_namespace(name)
41
+ namespace = ActiveSupport::Inflector.camelize(name)
42
+ namespace.split("::").reduce(Object) do |base, mod|
43
+ if base.const_defined?(mod)
44
+ base.const_get(mod)
45
+ else
46
+ base.const_set(mod, Module.new)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ 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
@@ -1,32 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support"
2
4
  require "pathname"
3
5
  require "rails"
4
6
 
5
7
  module Stimpack
6
8
  module Packs
7
- PATH = Pathname.new("packs").freeze
8
- PACK_CLASS = "Pack".freeze
9
+ PACK_CLASS = "Pack"
9
10
 
10
11
  class << self
11
12
  def resolve
12
- PATH.glob("**/#{Settings::PACK_CONFIG}").each do |path|
13
- path = path.dirname
14
- create(path.relative_path_from(PATH).to_s, path.expand_path)
15
- end
16
- end
13
+ # Gather all the directories with package config files.
14
+ paths = filter(Pack.root.glob("**/#{Pack::Configuration::FILE}").map(&:dirname).sort)
17
15
 
18
- def create(name, path)
19
- settings = Settings.new(name, path)
20
- namespace = create_namespace(settings.engine? ? Object : self, name)
21
- stim = Stim.new(settings, namespace)
22
- @packs[name] = namespace.const_set(PACK_CLASS, Class.new(Rails::Engine)).include(stim)
16
+ # Create thes packs.
17
+ paths.each do |path|
18
+ pack = Pack.new(path)
19
+ @packs[pack.name] = pack
20
+ end
23
21
  end
24
22
 
25
23
  def find(path)
26
24
  path = "#{path}/"
27
25
 
28
26
  @packs.values.find do |pack|
29
- path.start_with?("#{pack.root}/")
27
+ path.start_with?("#{pack.path}/")
30
28
  end
31
29
  end
32
30
 
@@ -40,13 +38,14 @@ module Stimpack
40
38
 
41
39
  private
42
40
 
43
- def create_namespace(base, name)
44
- namespace = ActiveSupport::Inflector.camelize(name)
45
- namespace.split("::").reduce(base) do |current_base, mod|
46
- if current_base.const_defined?(mod)
47
- current_base.const_get(mod)
48
- else
49
- current_base.const_set(mod, Module.new)
41
+ def filter(paths)
42
+ # Reject all paths that are nested since they might be just packwerk
43
+ # packages instead of packs.
44
+ paths.reject do |path|
45
+ path = "#{path}/"
46
+ paths.any? do |other_path|
47
+ other_path = "#{other_path}/"
48
+ path != other_path && path.start_with?(other_path)
50
49
  end
51
50
  end
52
51
  end
@@ -2,12 +2,8 @@ require "rails"
2
2
 
3
3
  module Stimpack
4
4
  class Railtie < Rails::Railtie
5
- config.before_configuration do
6
- Stimpack.start!
7
- end
8
-
9
- config.after_initialize do
10
- Stimpack.finalize!
5
+ config.before_configuration do |app|
6
+ Stimpack.load(app)
11
7
  end
12
8
  end
13
9
  end
data/lib/stimpack/stim.rb CHANGED
@@ -1,19 +1,28 @@
1
1
  module Stimpack
2
2
  class Stim < Module
3
- def initialize(settings, namespace)
4
- @settings = settings
3
+ def initialize(pack, namespace)
4
+ @pack = pack
5
5
  @namespace = namespace
6
6
  super()
7
7
  end
8
8
 
9
9
  def included(engine)
10
- engine.attr_accessor(:settings)
11
- engine.settings = @settings
12
- engine.called_from = @settings.path
10
+ engine.called_from = @pack.path
13
11
  engine.extend(ClassMethods)
12
+ engine.isolate_namespace(@namespace)
14
13
 
15
- if @settings.engine?
16
- engine.isolate_namespace(@namespace)
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::Integrations::Rails::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
17
26
  end
18
27
  end
19
28
 
@@ -1,3 +1,3 @@
1
1
  module Stimpack
2
- VERSION = "1.0.0.alpha5".freeze
2
+ VERSION = "1.0.0.alpha6".freeze
3
3
  end
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: 1.0.0.alpha5
4
+ version: 1.0.0.alpha6
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: 2021-02-22 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,10 +65,12 @@ files:
65
65
  - lib/stimpack.rb
66
66
  - lib/stimpack/integrations.rb
67
67
  - lib/stimpack/integrations/factory_bot.rb
68
+ - lib/stimpack/integrations/rails.rb
68
69
  - lib/stimpack/integrations/rspec.rb
70
+ - lib/stimpack/pack.rb
71
+ - lib/stimpack/pack/configuration.rb
69
72
  - lib/stimpack/packs.rb
70
73
  - lib/stimpack/railtie.rb
71
- - lib/stimpack/settings.rb
72
74
  - lib/stimpack/stim.rb
73
75
  - lib/stimpack/version.rb
74
76
  homepage: https://github.com/Gusto/stimpack
@@ -77,7 +79,7 @@ metadata:
77
79
  homepage_uri: https://github.com/Gusto/stimpack
78
80
  source_code_uri: https://github.com/Gusto/stimpack
79
81
  changelog_uri: https://github.com/Gusto/stimpack/blob/master/CHANGELOG.md
80
- post_install_message:
82
+ post_install_message:
81
83
  rdoc_options: []
82
84
  require_paths:
83
85
  - lib
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  version: 1.3.1
94
96
  requirements: []
95
97
  rubygems_version: 3.1.2
96
- signing_key:
98
+ signing_key:
97
99
  specification_version: 4
98
100
  summary: A Rails helper to package your code.
99
101
  test_files: []
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stimpack
4
- class Settings
5
- PACK_CONFIG = "package.yml"
6
-
7
- attr_reader :name
8
- attr_reader :path
9
-
10
- def initialize(name, path)
11
- @name = name
12
- @path = path
13
- end
14
-
15
- def relative_path
16
- @path.relative_path_from(Rails.root)
17
- end
18
-
19
- def engine
20
- config.fetch("engine", false)
21
- end
22
- alias_method :engine?, :engine
23
-
24
- private
25
-
26
- def config
27
- @config ||= begin
28
- package_config = YAML.load_file(path.join(PACK_CONFIG))
29
- package_config.fetch("metadata", {}).freeze
30
- end
31
- end
32
- end
33
- end