Repository navigation
ApiVersionChecker - Allow declarations before the methods - #404
Merged
Merged
Conversation
enforces_api_version and requires_api_version looked the methods up with instance_method as soon as they ran, so declaring them at the top of a class raised NameError. They now prepend a module whose methods run the check and then call the class's own method through super, so the declaration works before or after the methods it names. - Move the enforces_api_version declarations to the top of the 8 wrapper classes, right after include ApiVersionChecker - Add helper specs for declarations placed before the methods
Declaring before the methods means a misspelled name no longer raises when the class loads; it just leaves the intended method unchecked. - Prepend a named ApiVersionChecker::Check module that records the method names it wraps - Add a spec that loads the gem and fails if any class declares a method it doesn't define
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
enforces_api_versionandrequires_api_versionlooked each method up withinstance_methodas soon as they ran, so declaring them at the top of a class, before the methods, raisedNameErrorand broke the specs. This lets the declarations sit at the top of the class.Change
ApiVersionChecker::Checkmodule whose methods run the version check and then call the class's own method throughsuper. The class methods don't have to exist yet, so the declaration works before or after them. Arguments, keyword arguments and blocks are passed through as before.enforces_api_versiondeclarations in the 8 wrapper classes (AccountWebhooks,AnalyticsTags,ApiKeys,DomainKeys,Domains,MailingLists,Routes,Webhooks) move to the top, right afterinclude ApiVersionChecker.Guarding against typos
Declaring before the methods means a misspelled name no longer fails when the class loads; it would just leave the intended method unchecked.
Checkrecords the names it wraps, and a new spec loads every class that includes the checker and fails if any declared name isn't defined in that class. With:mtachadded to theRoutesdeclaration, it fails withMailgun::Routes#mtach.Testing
Mailgun::Tagsclass, which no spec covers (25% line coverage), and drop the suite below the 95% coverage minimum.