module Git::Repository::Stashing::Private
Private helpers local to {Git::Repository::Stashing}
@api private
Public Instance Methods
Source
# File lib/git/repository/stashing.rb, line 614 def split_pathspec_and_opts(pathspec) return [pathspec[0...-1], pathspec.last] if pathspec.last.is_a?(Hash) [pathspec, {}] end
Separate a trailing options Hash from a pathspec list
{Git::Repository::Stashing#stash_push} takes a variadic pathspec, so its options arrive as the last positional argument when present.
@example Pathspecs followed by options
Private.split_pathspec_and_opts(['a.rb', { message: 'WIP' }]) #=> [["a.rb"], { message: "WIP" }]
@example Pathspecs only
Private.split_pathspec_and_opts(['a.rb']) #=> [["a.rb"], {}]
@param pathspec [Array<String, Hash>] the positional arguments, possibly
ending in an options Hash
@return [Array(Array<String>, Hash)] the pathspecs and the options Hash
Source
# File lib/git/repository/stashing.rb, line 591 def split_stash_and_opts(stash, trailing) return [nil, stash] if stash.is_a?(Hash) && trailing.empty? [stash, trailing] end
Separate the stash operand from a positional options Hash
The stash-taking facade methods are declared ‘(stash = nil, opts = {})`. When the caller omits the stash and passes only options (`repo.stash_apply(index: true)`), Ruby binds the Hash to `stash`; this moves it to `opts` so both call shapes reach the command the same way.
@example Options passed without a stash
Private.split_stash_and_opts({ index: true }, {}) #=> [nil, { index: true }]
@example A stash and options
Private.split_stash_and_opts('stash@{1}', { index: true }) #=> ["stash@{1}", { index: true }]
@param stash [Git::StashInfo, String, Integer, Hash, nil] the stash
operand, or the options Hash when the stash was omitted
@param trailing [Hash] the second positional argument as bound by Ruby
@return [Array(Object, Hash)] the stash operand and the options Hash