Module: Lite::Command::Utils

Defined in:
lib/lite/command/utils.rb

Class Method Summary collapse

Class Method Details

.call(object, argument) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/lite/command/utils.rb', line 15

def call(object, argument)
  if argument.is_a?(Symbol) || argument.is_a?(String)
    object.send(argument)
  elsif argument.is_a?(Proc)
    object.instance_eval(&argument)
  else
    argument
  end
end

.evaluate(object, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/lite/command/utils.rb', line 25

def evaluate(object, options = {})
  if options[:if]
    call(object, options[:if])
  elsif options[:unless]
    !call(object, options[:unless])
  else
    options.fetch(:default, true)
  end
end

.try(object, method_name, *args, include_private: true) ⇒ Object



9
10
11
12
13
# File 'lib/lite/command/utils.rb', line 9

def try(object, method_name, *args, include_private: true)
  return unless object.respond_to?(method_name, include_private)

  object.send(method_name, *args)
end