Class: Verifly::Applicator::ProcApplicatior

Inherits:
Verifly::Applicator show all
Defined in:
lib/verifly/applicator.rb

Overview

ProcApplicatior is used when #to_proc is available. It works not only with procs, but also with hashes etc

Examples:

with a proc

Applicator.call(-> { foo }, binding_, *context) # => foo

with a hash

Applicator.call(Hash[foo: true], binding_, :foo) # => true
Applicator.call(Hash[foo: true], binding_, :bar) # => nil

Instance Attribute Summary

Attributes inherited from Verifly::Applicator

#applicable

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Verifly::Applicator

#==, call, #initialize

Methods included from ClassBuilder::Mixin

#build, #build_class, #buildable_classes=

Constructor Details

This class inherits a constructor from Verifly::Applicator

Class Method Details

.build_class(applicable) ⇒ Object

Parameters:

  • applicable (#to_proc)

Returns:

  • ProcApplicatior if applicable accepts #to_proc

  • (nil)

    otherwise



167
168
169
# File 'lib/verifly/applicator.rb', line 167

def self.build_class(applicable)
  self if applicable.respond_to?(:to_proc)
end

Instance Method Details

#call(binding_, *context) ⇒ Object

Returns application result.

Parameters:

  • binding_ (#instance_exec)

    target to apply applicable to

  • context

    additional info to send to applicable

Returns:

  • application result



174
175
176
# File 'lib/verifly/applicator.rb', line 174

def call(binding_, *context)
  invoke_lambda(applicable.to_proc, binding_, *context)
end

#sourceString

Returns Proc#source.

Returns:

  • (String)

    Proc#source



184
185
186
# File 'lib/verifly/applicator.rb', line 184

def source(*)
  applicable.to_proc.source
end

#source_locationString, Integer

Returns Proc#source_location.

Returns:

  • (String, Integer)

    Proc#source_location



179
180
181
# File 'lib/verifly/applicator.rb', line 179

def source_location(*)
  applicable.to_proc.source_location
end