From review feedback on #140 (https://github.com/d3mlabs/dev/blob/HEAD/lib/dev/cd/hook_installer.rb):
HookInstaller#ensure_installed currently returns Symbol | false (:added, :already_present, or false for an unsupported shell), which makes for a weak type and models the method's name poorly.
Ensuring the hook is installed is idempotent — a caller of an idempotent ensure has no business knowing whether the work was already done. The contract should be:
- Success = not raising. Drop
:already_present; the ensure either leaves the hook installed or raises.
- Unsupported shell raises a typed error (e.g.
UnsupportedShellError), caught at a higher level where the user-facing hint is printed.
Scope:
Note: some callers currently print different hints for "just added" vs "present but not active in this shell" — the refactor needs to either fold those messages into one, or surface that distinction some other way that doesn't leak the tri-state into the return type.
Requested by @JPDuchesne in #140 (comment) (thread on hook_installer.rb).
From review feedback on #140 (https://github.com/d3mlabs/dev/blob/HEAD/lib/dev/cd/hook_installer.rb):
HookInstaller#ensure_installedcurrently returnsSymbol | false(:added,:already_present, orfalsefor an unsupported shell), which makes for a weak type and models the method's name poorly.Ensuring the hook is installed is idempotent — a caller of an idempotent ensure has no business knowing whether the work was already done. The contract should be:
:already_present; the ensure either leaves the hook installed or raises.UnsupportedShellError), caught at a higher level where the user-facing hint is printed.Scope:
Dev::ShellRcHook#ensure_snippet(https://github.com/d3mlabs/dev/blob/HEAD/lib/dev/shell_rc_hook.rb) — the source of the tri-state return.Dev::Cd::HookInstaller#ensure_installed(https://github.com/d3mlabs/dev/blob/HEAD/lib/dev/cd/hook_installer.rb).Dev::Cd::Accessor(https://github.com/d3mlabs/dev/blob/HEAD/lib/dev/cd/accessor.rb),Dev::Clone::Accessor#announce(https://github.com/d3mlabs/dev/blob/HEAD/lib/dev/clone/accessor.rb), andDev::Builtins::UpCommand(https://github.com/d3mlabs/dev/blob/HEAD/src/dev/builtins/up_command.rb).Note: some callers currently print different hints for "just added" vs "present but not active in this shell" — the refactor needs to either fold those messages into one, or surface that distinction some other way that doesn't leak the tri-state into the return type.
Requested by @JPDuchesne in #140 (comment) (thread on hook_installer.rb).