Sha256: 9846051b821b709d323be06e440ac40d66df941b9952352ae008a8f7c5642c85

Contents?: true

Size: 637 Bytes

Versions: 3

Compression:

Stored size: 637 Bytes

Contents

# frozen_string_literal: true

class Shaped::Shapes::Callable < Shaped::Shape
  def initialize(callable)
    @callable = callable
  end

  def matched_by?(object)
    !!@callable.call(object)
  end

  def to_s
    case @callable
    when Method then "Method defined at #{@callable.source_location.map(&:to_s).join(':')}"
    when Proc
      if @callable.source_location
        "Proc test defined at #{@callable.source_location.map(&:to_s).join(':')}"
      else
        'Proc test defined at unknown location'
      end
    else "#call test defined at #{@callable.method(:call).source_location.map(&:to_s).join(':')}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shaped-0.14.0 lib/shaped/shapes/callable.rb
shaped-0.13.0 lib/shaped/shapes/callable.rb
shaped-0.12.0 lib/shaped/shapes/callable.rb