Skip to content
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

Deprecate constant lookups via .const_missing #10

Merged
merged 17 commits into from
Aug 16, 2021

Conversation

lanej
Copy link
Member

@lanej lanej commented Apr 12, 2021

Constant lookups are terrible. They cause cryptic errors and are hard to test without message expectations.

  • Store a simple hash-of-hashes to model the tree
  • Deprecate constant lookups by providing convenience functions using a simple variadic positional argument
Feature.enabled?(:new_feature, :available_for_presentation, user: OpenStruct.new(id: 12345)) # true

@lanej lanej changed the title Deprecate path lookups Deprecate constant lookups via .const_missing Apr 12, 2021
@lanej lanej requested a review from Roguelazer April 12, 2021 01:57
lib/toggles/feature.rb Outdated Show resolved Hide resolved
lib/toggles/constant_lookup.rb Outdated Show resolved Hide resolved
lib/toggles/constant_lookup.rb Show resolved Hide resolved
Copy link

@kgraves kgraves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me 👍

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@@ -0,0 +1,47 @@
class Feature::ConstantLookup
Error = Class.new(NameError) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just define this as, you know,

class Error < NameError do
   ...
end

Anonymous classes often feel like a code smell to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not an anonymous class, just a different way to declare a subclass.

Comment on lines +15 to +16
Error = Class.new(StandardError)
Unknown = Class.new(Error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question

@lanej lanej merged commit b30f19b into EasyPost:master Aug 16, 2021
@lanej lanej deleted the deprecate-path-lookups branch August 16, 2021 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants