Skip to content

Deprecate constant lookups via .const_missing#10

Merged
lanej merged 17 commits intoEasyPost:masterfrom
lanej:deprecate-path-lookups
Aug 16, 2021
Merged

Deprecate constant lookups via .const_missing#10
lanej merged 17 commits intoEasyPost:masterfrom
lanej:deprecate-path-lookups

Conversation

@lanej
Copy link
Copy Markdown
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 force-pushed the deprecate-path-lookups branch from 398e885 to 5a5e115 Compare April 12, 2021 01:47
@lanej lanej requested a review from Roguelazer April 12, 2021 01:57
@lanej lanej requested review from alirezaseifi and tpabla April 12, 2021 18:24
Copy link
Copy Markdown

@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 👍

@lanej lanej force-pushed the deprecate-path-lookups branch from 06cbf65 to 21deac3 Compare August 14, 2021 00:48
@@ -0,0 +1,47 @@
class Feature::ConstantLookup
Error = Class.new(NameError) do
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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