Class: FunWith::Files::Utils::Opts

Inherits:
Object
  • Object
show all
Defined in:
lib/fun_with/files/utils/opts.rb

Class Method Summary collapse

Class Method Details

.extract_opts_from_args(args) ⇒ Object

It’s tradition to pass an options hash as the last argument (creaky old tradition, named variables getting more popular) Separates out that last configuration hash, if it’s been given.



7
8
9
10
11
12
13
# File 'lib/fun_with/files/utils/opts.rb', line 7

def self.extract_opts_from_args( args )
  if args.last.is_a?( Hash )
    [args[0..-2], args.last ]
  else
    [args, {}]
  end
end

.narrow_file_utils_options(opts, cmd) ⇒ Object



20
21
22
# File 'lib/fun_with/files/utils/opts.rb', line 20

def self.narrow_file_utils_options( opts, cmd )
  self.narrow_options( opts, FileUtils::OPT_TABLE[ cmd.to_s ] )
end

.narrow_options(opts, keys) ⇒ Object

Given a hash and a list of keys, return a hash that only includes the keys listed.



16
17
18
# File 'lib/fun_with/files/utils/opts.rb', line 16

def self.narrow_options( opts, keys )
  opts.keep_if{ |k,v| keys.include?( k ) }
end