stimpack 0.8.0 → 0.8.1

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: 3b42399feb13f1a49d98931774e5b84d183fc7e1aa788e42e1687e5b08da0a7d
4
- data.tar.gz: 57032be9ad0ec238c44599f3261f2a24c30fb57a50b81981d5f832c42187f45d
3
+ metadata.gz: 46d22ca966c49e9a2f424291c0c44caec1ea24664c3239f1cca1fa4e218e91bf
4
+ data.tar.gz: 5a393fa3f27d5b9bcab1edf0d193f9a4cf7d64410d4184725b6cc26ac6e66679
5
5
  SHA512:
6
- metadata.gz: a03f395c7e10c89e6fb1e6757634aa70f3631106635d9da6236c6a828af8a5c7830670ca720ed656f77ece61e98d86ad52fad1b7a44affd9f1d88df68c402d2a
7
- data.tar.gz: c6cfbb618b10b21a5cf4ac0e465811236a269ef3210187870a47b1fd1043342ef3ee2b5fe0ea440a9f5c2dac57b4bdff495d9d04525ca3e5c5e1c90c7b9a9197
6
+ metadata.gz: 97ab5bfa795b0cd6008a13df1bb297e51191b5da2e561421e64b1fef71a80724709ffed50fdb66504102ca4625d532afb77564744564b8f77919c2aa3ff68b1b
7
+ data.tar.gz: 70eb5b61e2739cd657f31bd0ec79bc221f12ac3c0507365fec6701fda7deaae4839d0c127c6bab423ac3083b35852e03d0b5b0e4fd042245c894e45e48dce166
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  module Stimpack
2
4
  module Integrations
3
5
  class FactoryBot
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require "active_support/inflections"
4
5
 
@@ -14,17 +15,21 @@ module Stimpack
14
15
  end
15
16
 
16
17
  def create_engines
18
+ # Ideally, the user just does `Packs.configure { |config| config.roots = '...' }`
19
+ # But that would be a public API change and can come later
20
+ Packs.configure { |config| config.roots = Array(Stimpack.config.root) }
21
+
17
22
  Packs.all.each do |pack|
18
- next unless pack.config.engine?
23
+ next unless pack.metadata['engine']
19
24
 
20
- pack.engine = create_engine(pack)
25
+ create_engine(pack)
21
26
  end
22
27
  end
23
28
 
24
29
  def inject_paths
25
30
  Packs.all.each do |pack|
26
31
  Stimpack.config.paths.each do |path|
27
- @app.paths[path] << pack.path.join(path)
32
+ @app.paths[path] << pack.relative_path.join(path)
28
33
  end
29
34
  end
30
35
  end
@@ -43,8 +48,8 @@ module Stimpack
43
48
  end
44
49
 
45
50
  def create_engine(pack)
46
- name = pack.path.relative_path_from(Stimpack::Packs.root)
47
- namespace = create_namespace(pack.name)
51
+ name = pack.last_name
52
+ namespace = create_namespace(name)
48
53
  stim = Stim.new(pack, namespace)
49
54
  namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
50
55
  end
@@ -1,6 +1,10 @@
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)
@@ -10,6 +14,7 @@ module Stimpack
10
14
  # This is the default case when you run `rspec`. We want to add all the pack's spec paths
11
15
  # to the collection of directories to run.
12
16
 
17
+ Packs.configure { |config| config.roots = Array(Stimpack.config.root) }
13
18
  pack_paths = Packs.all.map do |pack|
14
19
  spec_path = pack.relative_path.join(default_path)
15
20
  spec_path.to_s if spec_path.exist?
@@ -26,10 +31,10 @@ module Stimpack
26
31
  # If it doesn't match a pack path, we leave it alone.
27
32
 
28
33
  to_run.map! do |path|
29
- if pack = Packs.all_by_path[path]
34
+ if pack = Packs.find(path)
30
35
  [
31
36
  pack,
32
- *Packs.all(pack)
37
+ *nested_packs_for(pack)
33
38
  ].map do |pack|
34
39
  spec_path = pack.relative_path.join(default_path)
35
40
  spec_path.to_s if spec_path.exist?
@@ -42,6 +47,13 @@ module Stimpack
42
47
 
43
48
  ::RSpec.configuration.files_or_directories_to_run = to_run.flatten.compact.uniq
44
49
  end
50
+
51
+ sig { params(parent_pack: Packs::Pack).returns(T::Array[Packs::Pack]) }
52
+ def nested_packs_for(parent_pack)
53
+ Packs.all.select do |pack|
54
+ pack.name != parent_pack.name && pack.name.include?(parent_pack.name)
55
+ end
56
+ end
45
57
  end
46
58
  end
47
59
  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.1".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
 
@@ -21,7 +21,8 @@ module Stimpack
21
21
  end
22
22
 
23
23
  @config = ActiveSupport::OrderedOptions.new
24
- @config.root = "packs".freeze
24
+ # Should this allow a plural version to be set? What are semantics of that?
25
+ @config.root = Array("packs".freeze)
25
26
  @config.paths = %w(
26
27
  app
27
28
  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.1
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-28 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