-
Notifications
You must be signed in to change notification settings - Fork 5
v1.1.0 - Extract plugin ceremony into automatic convenience methods on Team instances #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
e9a91fb
Add rspec binstub
joemsak da7338f
Add happy path of Plugin auto-helper-method
joemsak 6485514
Test nested data
joemsak 4878f96
Reset registered plugins during bust_caches
joemsak ef9b6be
Support all public instance methods on a given plugin
joemsak c17a9a5
Move test setup helpers into shared support with proper mixin config
joemsak e598d45
Remove Utils, not needed now
joemsak 849662c
Revert "Remove Utils, not needed now"
joemsak 6c17d08
Cannot support secondary methods yet
joemsak 8e2f67c
Add sorbet def
joemsak 69b298b
Add Utils.demodulize
joemsak 586b8f6
Add TODO for overriding Plugin.root_key
joemsak 46d3154
Add root_key overriding with declaration method
joemsak 2a23305
Bump version 1.0.2 -> 1.1.0
joemsak 323720e
Rename root_key to data_accessor_name
joemsak 7516410
Add integration for data_accessor_name override
joemsak 6e062fe
DRY up the integration test
joemsak 16adda5
Update README
joemsak da563a9
Formatting
joemsak 605df12
README formatting
joemsak 83fbcc6
README formatting
joemsak 38dc8c8
README formatting
joemsak c7f1052
Update README.md
joemsak daeb9b4
Add backward-compatibility integration spec
joemsak ede535d
PR feedback
joemsak 07444d3
Markdown indentation
joemsak c4cced2
refactor: use longform definition of modules over shorthand
vburzynski 7e18f42
style: fix rubocop Style/ModuleFunction issue
vburzynski 9b23a7b
Update spec/integration/plugin_helper_spec.rb
joemsak 834ea3b
Update code_teams.rb
joemsak c640b92
Update code_teams.rb
joemsak 99ec754
Update code_teams.rb
joemsak d9e2bfd
Update plugin.rb
joemsak 8ffb2a0
Update .rubocop.yml
joemsak 070c7a0
Update plugin_helper_spec.rb
joemsak 16fe1a7
Fix rubocop target version, io helpers, helper usage
joemsak f18d7b6
Ruby 3.2 maintenance
joemsak 5ce0dca
Sorbet issues fixed
joemsak 7384e03
Update the bundle
joemsak a29287e
Add tapioca and ignore vendor/bundle
joemsak 0f4d661
Rubocop
joemsak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| /doc/ | ||
| /pkg/ | ||
| /spec/reports/ | ||
| /vendor/bundle | ||
| /tmp/ | ||
|
|
||
| # rspec failure tracking | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| # | ||
| # This file was generated by Bundler. | ||
| # | ||
| # The application 'rspec' is installed as part of a gem, and | ||
| # this file is here to facilitate running it. | ||
| # | ||
|
|
||
| ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
|
|
||
| bundle_binstub = File.expand_path("bundle", __dir__) | ||
|
|
||
| if File.file?(bundle_binstub) | ||
| if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") | ||
| load(bundle_binstub) | ||
| else | ||
| abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
| Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
| end | ||
| end | ||
|
|
||
| require "rubygems" | ||
| require "bundler/setup" | ||
|
|
||
| load Gem.bin_path("rspec-core", "rspec") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| module CodeTeams | ||
| module Utils | ||
| module_function | ||
|
|
||
| def underscore(string) | ||
| string.gsub('::', '/') | ||
| .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') | ||
| .gsub(/([a-z\d])([A-Z])/, '\1_\2') | ||
| .tr('-', '_') | ||
| .downcase | ||
| end | ||
|
|
||
| def demodulize(string) | ||
| string.split('::').last | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ | |
| # typed: strong | ||
| module ::RSpec; end | ||
| module ::TestPlugin; end | ||
| module TestNamespace::TestPlugin; end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| RSpec.describe CodeTeams::Plugin do | ||
| before do | ||
| CodeTeams.bust_caches! | ||
| write_team_yml(extra_data: { 'foo' => 'foo', 'bar' => 'bar' }) | ||
| end | ||
|
|
||
| let(:team) { CodeTeams.find('My Team') } | ||
|
|
||
| describe 'helper methods' do | ||
| context 'with a single implicit method' do | ||
| before do | ||
| test_plugin_class = Class.new(described_class) do | ||
| def test_plugin | ||
| data = @team.raw_hash['extra_data'] | ||
| Data.define(:foo, :bar).new(data['foo'], data['bar']) | ||
| end | ||
| end | ||
|
|
||
| stub_const('TestPlugin', test_plugin_class) | ||
| end | ||
|
|
||
| it 'adds a helper method to the team' do | ||
| expect(team.test_plugin.foo).to eq('foo') | ||
| expect(team.test_plugin.bar).to eq('bar') | ||
| end | ||
|
|
||
| it 'supports nested data' do | ||
| write_team_yml(extra_data: { 'foo' => { 'bar' => 'bar' } }) | ||
| expect(team.test_plugin.foo['bar']).to eq('bar') | ||
| end | ||
| end | ||
|
|
||
| context 'when the data accessor name is overridden' do | ||
| before do | ||
| test_plugin_class = Class.new(described_class) do | ||
| data_accessor_name 'foo' | ||
|
|
||
| def foo | ||
| Data.define(:bar).new('bar') | ||
| end | ||
| end | ||
|
|
||
| stub_const('TestPlugin', test_plugin_class) | ||
| end | ||
|
|
||
| it 'adds the data accessor name to the team' do | ||
| expect(team.foo.bar).to eq('bar') | ||
| end | ||
| end | ||
| end | ||
|
|
||
| specify 'backwards compatibility' do | ||
| test_plugin_class = Class.new(described_class) do | ||
| def test_plugin | ||
| Data.define(:foo).new('foo') | ||
| end | ||
| end | ||
|
|
||
| stub_const('TestPlugin', test_plugin_class) | ||
|
|
||
| expect(TestPlugin.for(team).test_plugin.foo).to eq('foo') | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,41 @@ | ||
| RSpec.describe CodeTeams::Plugin do | ||
| def write_team_yml(extra_data: false) | ||
| write_file('config/teams/my_team.yml', <<~YML.strip) | ||
| name: My Team | ||
| extra_data: #{extra_data} | ||
| YML | ||
| end | ||
|
|
||
| before do | ||
| CodeTeams.bust_caches! | ||
|
|
||
| test_plugin_class = Class.new(described_class) do | ||
| def extra_data | ||
| @team.raw_hash['extra_data'] | ||
| end | ||
| end | ||
| stub_const('TestPlugin', test_plugin_class) | ||
| end | ||
| module TestNamespace; end | ||
|
|
||
| RSpec.describe CodeTeams::Plugin do | ||
| describe '.bust_caches!' do | ||
| it 'clears all plugins team registries ensuring cached configs are purged' do | ||
| test_plugin_class = Class.new(described_class) do | ||
| def extra_data | ||
| @team.raw_hash['extra_data'] | ||
| end | ||
| end | ||
| stub_const('TestNamespace::TestPlugin', test_plugin_class) | ||
|
|
||
| CodeTeams.bust_caches! | ||
| write_team_yml(extra_data: true) | ||
| team = CodeTeams.find('My Team') | ||
| expect(TestPlugin.for(team).extra_data).to be(true) | ||
| expect(TestNamespace::TestPlugin.for(team).extra_data).to be(true) | ||
| write_team_yml(extra_data: false) | ||
| CodeTeams.bust_caches! | ||
| team = CodeTeams.find('My Team') | ||
| expect(TestPlugin.for(team).extra_data).to be(false) | ||
| expect(TestNamespace::TestPlugin.for(team).extra_data).to be(false) | ||
| end | ||
| end | ||
|
|
||
| describe '.data_accessor_name' do | ||
| it 'returns the underscore version of the plugin name' do | ||
| test_plugin_class = Class.new(described_class) | ||
| stub_const('TestNamespace::TestPlugin', test_plugin_class) | ||
|
|
||
| expect(TestNamespace::TestPlugin.data_accessor_name).to eq('test_plugin') | ||
| end | ||
|
|
||
| it 'can be overridden by a subclass' do | ||
| test_plugin_class = Class.new(described_class) do | ||
| data_accessor_name 'foo' | ||
| end | ||
| stub_const('TestNamespace::TestPlugin', test_plugin_class) | ||
|
|
||
| expect(TestNamespace::TestPlugin.data_accessor_name).to eq('foo') | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.