class Verifly::Applicator

@abstract implement `#call`, `#source` and `#source_location` Applies “applicable” objects to given bindings (applicable objects are named based on their use, currently any object is applicable).

This class uses ClassBuilder system. When reading the code, we suggest starting from '.call' method @see ClassBuilder @attr applicable [applicable] wrapped applicable object

Attributes

applicable[RW]

Public Class Methods

call(applicable, binding_, *context) click to toggle source

Applies applicable on binding_ with context @param applicable [applicable]

see examples in definitions of subclasses

@param binding_ [#instance_exec]

where should applicable be applied. It could be either a generic object,
where it would be `instance_exec`uted, or a binding_

@param context

geneneric data you want to pass to applicable function.
If applicable cannot accept params, context will not be sent

@return application result

# File lib/verifly/applicator.rb, line 225
def self.call(applicable, binding_, *context)
  build(applicable).call(binding_, *context)
end
new(applicable) click to toggle source

Always use build instead of new @todo add more examples right here @param applicable [applicable]

see examples in definitions of sublclasses

@api private

# File lib/verifly/applicator.rb, line 234
def initialize(applicable)
  self.applicable = applicable
end

Public Instance Methods

==(other) click to toggle source

@param [Applicator] other @return [Boolean] true if applicable matches, false otherwise

# File lib/verifly/applicator.rb, line 240
def ==(other)
  applicable == other.applicable
end

Private Instance Methods

invoke_lambda(lambda, binding_, *context) click to toggle source

invokes lambda respecting its arity @param [Proc] lambda @param binding_ [#instance_exec] binding_ would be used in application @param context param would be passed if lambda arity > 0 @return invocation result

# File lib/verifly/applicator.rb, line 268
def invoke_lambda(lambda, binding_, *context)
  if lambda.arity.zero?
    binding_.instance_exec(&lambda)
  else
    binding_.instance_exec(*context, &lambda)
  end
end