Class: NxtSchema::Callable

Inherits:
Object
  • Object
show all
Defined in:
lib/nxt_schema/callable.rb

Instance Method Summary collapse

Constructor Details

#initialize(callable, target = nil, *args) ⇒ Callable

Returns a new instance of Callable.



3
4
5
6
7
# File 'lib/nxt_schema/callable.rb', line 3

def initialize(callable, target = nil, *args)
  @callable = callable
  @target = target
  @args = args
end

Instance Method Details

#callObject



9
10
11
12
13
14
# File 'lib/nxt_schema/callable.rb', line 9

def call
  return callable if value?
  return callable.call(*args_from_arity) if proc?

  target.send(callable, *args_from_arity)
end

#method?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/nxt_schema/callable.rb', line 16

def method?
  @method ||= callable.class.in?([Symbol, String]) && target.respond_to?(callable)
end

#proc?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/nxt_schema/callable.rb', line 20

def proc?
  @proc ||= callable.respond_to?(:call)
end

#value?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/nxt_schema/callable.rb', line 24

def value?
  !method? && !proc?
end