stimpack 0.8.0 → 0.8.2

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: 3b42399feb13f1a49d98931774e5b84d183fc7e1aa788e42e1687e5b08da0a7d
4
- data.tar.gz: 57032be9ad0ec238c44599f3261f2a24c30fb57a50b81981d5f832c42187f45d
3
+ metadata.gz: 5c1c50146a16145446bf9b0bc74d29d19f8cb62fe9194a98d7767163ab5ffe31
4
+ data.tar.gz: 335d8aaaf0fcd39058d2379d646f4fa1c4ba02c811b70dfc90e316668be35004
5
5
  SHA512:
6
- metadata.gz: a03f395c7e10c89e6fb1e6757634aa70f3631106635d9da6236c6a828af8a5c7830670ca720ed656f77ece61e98d86ad52fad1b7a44affd9f1d88df68c402d2a
7
- data.tar.gz: c6cfbb618b10b21a5cf4ac0e465811236a269ef3210187870a47b1fd1043342ef3ee2b5fe0ea440a9f5c2dac57b4bdff495d9d04525ca3e5c5e1c90c7b9a9197
6
+ metadata.gz: 69ab74f37e4eb0980c8ef7c383c54953acc9a80f442b7513f6ce5ba9ca6f328499a6bd1f81f3ef8590d720456cbf453fca24854dbb7704313797ca709aafe7af
7
+ data.tar.gz: 18bb1001c9d8da9c055202d65ee55e8dbf9c83f3d445999bbf18bc05e7650113d0acd4dc5c1df1d7a742e5e8d11b4683b61c171b5e1b86ab293262f83aee45c6
@@ -1,10 +1,14 @@
1
+ # typed: true
2
+
1
3
  module Stimpack
2
4
  module Integrations
3
5
  class FactoryBot
4
6
  def initialize(app)
5
7
  return unless app.config.respond_to?(:factory_bot)
8
+ Stimpack.configure_packs
6
9
 
7
10
  Packs.all.each do |pack|
11
+ next if pack.relative_path.glob('*.gemspec').any?
8
12
  app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
9
13
  end
10
14
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require "active_support/inflections"
4
5
 
@@ -9,22 +10,24 @@ module Stimpack
9
10
  @app = app
10
11
 
11
12
  Stimpack.config.paths.freeze
13
+ Stimpack.configure_packs
14
+
12
15
  create_engines
13
16
  inject_paths
14
17
  end
15
18
 
16
19
  def create_engines
17
20
  Packs.all.each do |pack|
18
- next unless pack.config.engine?
21
+ next unless pack.metadata['engine']
19
22
 
20
- pack.engine = create_engine(pack)
23
+ create_engine(pack)
21
24
  end
22
25
  end
23
26
 
24
27
  def inject_paths
25
28
  Packs.all.each do |pack|
26
29
  Stimpack.config.paths.each do |path|
27
- @app.paths[path] << pack.path.join(path)
30
+ @app.paths[path] << pack.relative_path.join(path)
28
31
  end
29
32
  end
30
33
  end
@@ -43,8 +46,8 @@ module Stimpack
43
46
  end
44
47
 
45
48
  def create_engine(pack)
46
- name = pack.path.relative_path_from(Stimpack::Packs.root)
47
- namespace = create_namespace(pack.name)
49
+ name = pack.last_name
50
+ namespace = create_namespace(name)
48
51
  stim = Stim.new(pack, namespace)
49
52
  namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
50
53
  end
@@ -1,11 +1,17 @@
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)
7
11
  default_path = ::RSpec.configuration.default_path
8
12
 
13
+ Stimpack.configure_packs
14
+
9
15
  if to_run == [default_path]
10
16
  # This is the default case when you run `rspec`. We want to add all the pack's spec paths
11
17
  # to the collection of directories to run.
@@ -26,10 +32,10 @@ module Stimpack
26
32
  # If it doesn't match a pack path, we leave it alone.
27
33
 
28
34
  to_run.map! do |path|
29
- if pack = Packs.all_by_path[path]
35
+ if pack = Packs.find(path)
30
36
  [
31
37
  pack,
32
- *Packs.all(pack)
38
+ *nested_packs_for(pack)
33
39
  ].map do |pack|
34
40
  spec_path = pack.relative_path.join(default_path)
35
41
  spec_path.to_s if spec_path.exist?
@@ -42,6 +48,13 @@ module Stimpack
42
48
 
43
49
  ::RSpec.configuration.files_or_directories_to_run = to_run.flatten.compact.uniq
44
50
  end
51
+
52
+ sig { params(parent_pack: Packs::Pack).returns(T::Array[Packs::Pack]) }
53
+ def nested_packs_for(parent_pack)
54
+ Packs.all.select do |pack|
55
+ pack.name != parent_pack.name && pack.name.include?(parent_pack.name)
56
+ end
57
+ end
45
58
  end
46
59
  end
47
60
  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.path
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
@@ -1,3 +1,3 @@
1
1
  module Stimpack
2
- VERSION = "0.8.0".freeze
2
+ VERSION = "0.8.2".freeze
3
3
  end
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
 
@@ -18,10 +18,28 @@ module Stimpack
18
18
  def root
19
19
  @root ||= Rails::Application.find_root(Dir.pwd)
20
20
  end
21
+
22
+ #
23
+ # This is temporary. For now, we allow Stimpack roots to be configured via Stimpack.config.root
24
+ # Later, if clients configure packs directly, we can deprecate the Stimpack setting and
25
+ # remove this function and its invocations.
26
+ #
27
+ def configure_packs
28
+ Packs.configure do |config|
29
+ roots = Array(Stimpack.config.root)
30
+ pack_paths = roots.flat_map do |root|
31
+ # Support nested packs by default. Later, this can be pushed to a client configuration.
32
+ ["#{root}/*", "#{root}/*/*"]
33
+ end
34
+
35
+ config.pack_paths = pack_paths
36
+ end
37
+ end
21
38
  end
22
39
 
23
40
  @config = ActiveSupport::OrderedOptions.new
24
- @config.root = "packs".freeze
41
+ # Should this allow a plural version to be set? What are semantics of that?
42
+ @config.root = Array("packs".freeze)
25
43
  @config.paths = %w(
26
44
  app
27
45
  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.8.0
4
+ version: 0.8.2
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: 2022-12-08 00:00:00.000000000 Z
11
+ date: 2022-12-29 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
@@ -152,7 +163,7 @@ metadata:
152
163
  homepage_uri: https://github.com/Gusto/stimpack
153
164
  source_code_uri: https://github.com/Gusto/stimpack
154
165
  changelog_uri: https://github.com/Gusto/stimpack/blob/master/CHANGELOG.md
155
- post_install_message:
166
+ post_install_message:
156
167
  rdoc_options: []
157
168
  require_paths:
158
169
  - lib
@@ -167,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
178
  - !ruby/object:Gem::Version
168
179
  version: '0'
169
180
  requirements: []
170
- rubygems_version: 3.3.25
171
- signing_key:
181
+ rubygems_version: 3.1.6
182
+ signing_key:
172
183
  specification_version: 4
173
184
  summary: A Rails helper to package your code.
174
185
  test_files: []
@@ -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
@@ -1,48 +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
- matched_path = @find_pack_paths.find do |pack_path|
18
- path.start_with?(pack_path)
19
- end
20
- all_by_path.fetch(matched_path.chomp("/")) if matched_path
21
- end
22
-
23
- def all(parent = nil)
24
- @all ||= resolve(root).each_with_object({}) do |pack, map|
25
- map[pack] = resolve(pack.path).freeze
26
- end.freeze
27
-
28
- if parent
29
- @all[parent]
30
- else
31
- @all.keys + @all.values.flatten
32
- end
33
- end
34
-
35
- def all_by_path
36
- @all_by_path ||= all.each_with_object({}) do |pack, map|
37
- map[pack.relative_path.to_s] = pack
38
- end
39
- end
40
-
41
- private
42
-
43
- def resolve(directory)
44
- directory.glob(PACKAGE_GLOB_PATTERN).map { |path| Pack.new(path.dirname) }
45
- end
46
- end
47
- end
48
- end