module Eqq

Pattern objects builder

Constants

VERSION

This will be same as latest published gem version

Public Class Methods

build(&block) click to toggle source

@return [Proc] @raise [InvalidProductError] if the return value is not looks to be built with builders

# File lib/eqq.rb, line 43
def build(&block)
  raise ArgumentError, 'might be mis used the `Eqq.build` in your code' unless block

  pattern = DSLScope.new.instance_exec(&block)
  raise InvalidProductError, 'might be mis used the `Eqq.build` in your code' unless satisfy?(pattern)

  pattern
end
define(&block) click to toggle source

@deprecated Use {build} instead. This will be dropped since `0.1.0`

# File lib/eqq.rb, line 53
def define(&block)
  build(&block)
end
pattern?(object) click to toggle source
# File lib/eqq.rb, line 18
def pattern?(object)
  case object
  when Proc, Method
    object.arity == 1
  else
    begin
      object.respond_to?(:===)
    rescue NoMethodError
      false
    end
  end
end
satisfy?(object) click to toggle source

@api private

# File lib/eqq.rb, line 37
def satisfy?(object)
  (Proc === object) && object.lambda? && (object.arity == 1) && object.respond_to?(:inspect)
end
valid?(object) click to toggle source

@deprecated Use {pattern?} instead. This will be dropped since `0.1.0`

# File lib/eqq.rb, line 32
def valid?(object)
  pattern?(object)
end