stimpack 0.4.0 → 0.7.0

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: 3cb6166834b2ea8ebd3623491464ee321b457fc4347c7f8af80e8efa47c18785
4
- data.tar.gz: b165b651e620abd0197c509070049a2f9ff5523f2b5c4ab32b2b7d26392c8b16
3
+ metadata.gz: a0fa94f149c0035eb12465252c3262c7bea9df7fad9ea00efb5014d6484b00d1
4
+ data.tar.gz: a20a5aad13953de01410054b99e3bd2932df56a9e879edc6a14bd3601baca0ba
5
5
  SHA512:
6
- metadata.gz: 81f1124b9c8901a6a681f00385f9a5d67c48d035925c241b69ab68f0c9745d7b4c15decd45d59b1fceb6d9b552ec23c4431f900a230f77ef1954c5edba740bf0
7
- data.tar.gz: e4c881c3356dab09454183967508051133a1054054fc10dc9106cae7fb5b2ef3378ff5c68da93dcfb119e55004144cb539c70ebf8c875ca9e301a4ecdafd2e94
6
+ metadata.gz: a7634623fc5fb02369e979fd62f1d816dafc734eacd0d2bab2a47acdce9ec1eeb1b29eccbb88193263623feb3eb94ccf1929065e919bd8d787fce43300dcafbb
7
+ data.tar.gz: 700f5b8c757d98b6340fb55dee4812c86d449162e65aa1a4946eb5557981ef5b37b306b2f7327703e6f6ddfcd5024db0eb60112c7b087170204704b1ba71fa70
data/README.md CHANGED
@@ -92,6 +92,35 @@ metadata:
92
92
  engine: true
93
93
  ```
94
94
 
95
+ ### RSpec Integration
96
+ Simply add `--require stimpack/rspec` to your `.rspec`.
97
+ Or, if you'd like, pass it as an argument to `rspec`:
98
+
99
+ ```
100
+ $ rspec --require stimpack/rspec ...
101
+ ```
102
+
103
+ Integration will allow you to run tests as such:
104
+ ```
105
+ # Run all specs in your entire application (packs and all):
106
+ rspec
107
+
108
+ # Run just that one test:
109
+ rspec spec/some/specific_spec.rb
110
+
111
+ # Run all tests under the "foobar" pack and all the tests of its nested packs:
112
+ rspec packs/foobar
113
+
114
+ # Same as above but also adds the "binbaz" pack:
115
+ rspec packs/foobar pack/binbaz
116
+
117
+ # Run all test files inside the "packs/foobar/spec" directory:
118
+ rspec packs/foobar/spec
119
+
120
+ # Run all specs under the "packs/foobar/nested_pack" pack:
121
+ rspec packs/foobar/nested_pack
122
+ ```
123
+
95
124
  ## Contributing
96
125
 
97
126
  Bug reports and pull requests are welcome on GitHub at https://github.com/Gusto/stimpack.
data/bin/tapioca ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'tapioca' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("tapioca", "tapioca")
@@ -1,10 +1,10 @@
1
1
  module Stimpack
2
2
  module Integrations
3
3
  class FactoryBot
4
- def self.install(app)
4
+ def initialize(app)
5
5
  return unless app.config.respond_to?(:factory_bot)
6
6
 
7
- Packs.each do |pack|
7
+ Packs.all.each do |pack|
8
8
  app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
9
9
  end
10
10
  end
@@ -1,17 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/inflections"
4
+
3
5
  module Stimpack
4
6
  module Integrations
5
7
  class Rails
6
- def self.install(app)
8
+ def initialize(app)
9
+ @app = app
10
+
7
11
  Stimpack.config.paths.freeze
12
+ create_engines
13
+ inject_paths
14
+ end
15
+
16
+ def create_engines
17
+ Packs.all.each do |pack|
18
+ next unless pack.config.engine?
19
+
20
+ pack.engine = create_engine(pack)
21
+ end
22
+ end
8
23
 
9
- Packs.each do |pack|
24
+ def inject_paths
25
+ Packs.all.each do |pack|
10
26
  Stimpack.config.paths.each do |path|
11
- app.paths[path] << pack.path.join(path)
27
+ @app.paths[path] << pack.path.join(path)
12
28
  end
13
29
  end
14
30
  end
31
+
32
+ private
33
+
34
+ def create_namespace(name)
35
+ namespace = ActiveSupport::Inflector.camelize(name)
36
+ namespace.split("::").reduce(Object) do |base, mod|
37
+ if base.const_defined?(mod, false)
38
+ base.const_get(mod, false)
39
+ else
40
+ base.const_set(mod, Module.new)
41
+ end
42
+ end
43
+ end
44
+
45
+ def create_engine(pack)
46
+ name = pack.path.relative_path_from(Stimpack::Packs.root)
47
+ namespace = create_namespace(pack.name)
48
+ stim = Stim.new(pack, namespace)
49
+ namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
50
+ end
15
51
  end
16
52
  end
17
53
  end
@@ -1,12 +1,46 @@
1
1
  module Stimpack
2
2
  module Integrations
3
3
  class RSpec
4
- def self.install(app)
5
- return unless defined?(::RSpec)
4
+ def initialize
5
+ # This is the list of directories RSpec was told to run.
6
+ to_run = ::RSpec.configuration.instance_variable_get(:@files_or_directories_to_run)
7
+ default_path = ::RSpec.configuration.default_path
6
8
 
7
- Packs.each do |pack|
8
- ::RSpec.configuration.pattern.concat(",#{pack.relative_path.join("spec/**/*_spec.rb")}")
9
+ if to_run == [default_path]
10
+ # This is the default case when you run `rspec`. We want to add all the pack's spec paths
11
+ # to the collection of directories to run.
12
+
13
+ pack_paths = Packs.all.map do |pack|
14
+ spec_path = pack.relative_path.join(default_path)
15
+ spec_path.to_s if spec_path.exist?
16
+ end
17
+
18
+ to_run.concat(pack_paths)
19
+ else
20
+ # This is when `rspec` is run with a list of directories or files. We scan this list to see
21
+ # if any of them matches a pack's directory. If it does, we concat the `default_path` to the
22
+ # end of it.
23
+ #
24
+ # packs/my_pack => packs/my_pack/spec
25
+ #
26
+ # If it doesn't match a pack path, we leave it alone.
27
+
28
+ to_run.map! do |path|
29
+ if pack = Packs.all_by_path[path]
30
+ [
31
+ pack,
32
+ *Packs.all(pack)
33
+ ].map do |pack|
34
+ spec_path = pack.relative_path.join(default_path)
35
+ spec_path.to_s if spec_path.exist?
36
+ end
37
+ else
38
+ path
39
+ end
40
+ end
9
41
  end
42
+
43
+ ::RSpec.configuration.files_or_directories_to_run = to_run.flatten.compact.uniq
10
44
  end
11
45
  end
12
46
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "yaml"
4
+
3
5
  module Stimpack
4
6
  class Pack
5
7
  class Configuration
@@ -17,7 +19,11 @@ module Stimpack
17
19
  private
18
20
 
19
21
  def data
20
- @data ||= YAML.load_file(@path).fetch(KEY, {}).freeze
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
21
27
  end
22
28
  end
23
29
  end
data/lib/stimpack/pack.rb CHANGED
@@ -1,53 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
4
+
3
5
  module Stimpack
4
6
  class Pack
5
7
  PACKAGE_FILE = "package.yml"
6
8
 
7
9
  autoload :Configuration, "stimpack/pack/configuration"
8
10
 
9
- attr_reader :name
10
11
  attr_reader :path
11
- attr_reader :engine
12
-
13
- def self.create(path)
14
- new(path) if path.join(PACKAGE_FILE).exist?
15
- end
12
+ attr_reader :name
13
+ attr_accessor :engine
16
14
 
17
15
  def initialize(path)
18
16
  @path = path
19
- @name = path.relative_path_from(Packs.root)
20
-
21
- if config.engine?
22
- @engine = create_engine
23
- end
17
+ @name = path.basename.to_s
24
18
  end
25
19
 
26
20
  def relative_path
27
- @relative_path ||= path.relative_path_from(Rails.root)
21
+ @relative_path ||= path.relative_path_from(Stimpack.root)
28
22
  end
29
23
 
30
24
  def config
31
25
  @config ||= Configuration.new(path.join(PACKAGE_FILE))
32
26
  end
33
-
34
- private
35
-
36
- def create_engine
37
- namespace = create_namespace(name)
38
- stim = Stim.new(self, namespace)
39
- namespace.const_set("Engine", Class.new(Rails::Engine)).include(stim)
40
- end
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
27
  end
53
28
  end
@@ -1,42 +1,47 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
- require "pathname"
5
- require "rails"
6
4
 
7
5
  module Stimpack
8
6
  module Packs
7
+ PACKAGE_GLOB_PATTERN = "*/#{Pack::PACKAGE_FILE}"
8
+
9
9
  class << self
10
10
  def root
11
- @root ||= Rails.root.join(Stimpack.config.root)
11
+ @root ||= Stimpack.root.join(Stimpack.config.root)
12
12
  end
13
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
- next unless pack = Pack.create(path)
18
- @packs[pack.name] = pack
14
+ def find(path)
15
+ @find_pack_paths ||= all_by_path.keys.sort_by(&:length).reverse!.map { |path| "#{path}/" }
16
+ path = "#{path}/"
17
+ @find_pack_paths.find do |pack_path|
18
+ path.start_with?(pack_path)
19
19
  end
20
- @packs.freeze
21
20
  end
22
21
 
23
- def find(path)
24
- path = "#{path}/"
22
+ def all(parent = nil)
23
+ @all ||= resolve(root).each_with_object({}) do |pack, map|
24
+ map[pack] = resolve(pack.path).freeze
25
+ end.freeze
25
26
 
26
- @packs.values.find do |pack|
27
- path.start_with?("#{pack.path}/")
27
+ if parent
28
+ @all[parent]
29
+ else
30
+ @all.keys + @all.values.flatten
28
31
  end
29
32
  end
30
33
 
31
- def [](name)
32
- @packs[name]
34
+ def all_by_path
35
+ @all_by_path ||= all.each_with_object({}) do |pack, map|
36
+ map[pack.relative_path.to_s] = pack
37
+ end
33
38
  end
34
39
 
35
- def each(*args, &block)
36
- @packs.each_value(*args, &block)
40
+ private
41
+
42
+ def resolve(directory)
43
+ directory.glob(PACKAGE_GLOB_PATTERN).map { |path| Pack.new(path.dirname) }
37
44
  end
38
45
  end
39
-
40
- @packs = {}
41
46
  end
42
47
  end
@@ -1,9 +1,13 @@
1
- require "rails"
1
+ require "rails/railtie"
2
2
 
3
3
  module Stimpack
4
4
  class Railtie < Rails::Railtie
5
5
  config.before_configuration do |app|
6
- Stimpack.load(app)
6
+ Integrations::Rails.new(app)
7
+ Integrations::FactoryBot.new(app)
8
+
9
+ # This is not used within stimpack. Rather, this allows OTHER tools to
10
+ # hook into Stimpack via ActiveSupport hooks.
7
11
  ActiveSupport.run_load_hooks(:stimpack, Packs)
8
12
  end
9
13
  end
@@ -0,0 +1,3 @@
1
+ require "stimpack"
2
+
3
+ Stimpack::Integrations::RSpec.new
@@ -1,3 +1,3 @@
1
1
  module Stimpack
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.7.0".freeze
3
3
  end
data/lib/stimpack.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "active_support"
2
+ require "rails/application"
2
3
 
3
4
  module Stimpack
4
5
  extend ActiveSupport::Autoload
@@ -14,16 +15,8 @@ module Stimpack
14
15
  class << self
15
16
  attr_reader :config
16
17
 
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]
18
+ def root
19
+ @root ||= Rails::Application.find_root(Dir.pwd)
27
20
  end
28
21
  end
29
22
 
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.4.0
4
+ version: 0.7.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: 2022-06-02 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,7 +52,50 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Package your code.
55
+ - !ruby/object:Gem::Dependency
56
+ name: debug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sorbet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tapioca
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: stimpack establishes and implements a set of conventions for splitting
98
+ up large monoliths.
56
99
  email:
57
100
  - gusto-opensource-buildkite@gusto.com
58
101
  executables: []
@@ -62,6 +105,7 @@ files:
62
105
  - README.md
63
106
  - bin/console
64
107
  - bin/setup
108
+ - bin/tapioca
65
109
  - lib/stimpack.rb
66
110
  - lib/stimpack/integrations.rb
67
111
  - lib/stimpack/integrations/factory_bot.rb
@@ -71,6 +115,7 @@ files:
71
115
  - lib/stimpack/pack/configuration.rb
72
116
  - lib/stimpack/packs.rb
73
117
  - lib/stimpack/railtie.rb
118
+ - lib/stimpack/rspec.rb
74
119
  - lib/stimpack/stim.rb
75
120
  - lib/stimpack/version.rb
76
121
  homepage: https://github.com/Gusto/stimpack
@@ -79,7 +124,7 @@ metadata:
79
124
  homepage_uri: https://github.com/Gusto/stimpack
80
125
  source_code_uri: https://github.com/Gusto/stimpack
81
126
  changelog_uri: https://github.com/Gusto/stimpack/blob/master/CHANGELOG.md
82
- post_install_message:
127
+ post_install_message:
83
128
  rdoc_options: []
84
129
  require_paths:
85
130
  - lib
@@ -94,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
139
  - !ruby/object:Gem::Version
95
140
  version: '0'
96
141
  requirements: []
97
- rubygems_version: 3.2.32
98
- signing_key:
142
+ rubygems_version: 3.3.7
143
+ signing_key:
99
144
  specification_version: 4
100
145
  summary: A Rails helper to package your code.
101
146
  test_files: []