Sha256: 7b789b830937e08d63bab54c0aacc6c602a71e0e27cc16b172da2596894f3154

Contents?: true

Size: 877 Bytes

Versions: 19

Compression:

Stored size: 877 Bytes

Contents

module Finitio
  class Constraint
    include Metadata

    def initialize(native, name = nil, metadata = nil)
      unless native.respond_to?(:===)
        raise ArgumentError, "Constraint must respond to :==="
      end
      unless name.nil? or name.is_a?(Symbol)
        raise ArgumentError, "Constraint name must be a Symbol"
      end
      @native = native
      @name = name
      @metadata = metadata
    end

    attr_reader :native
    protected :native

    def anonymous?
      @name.nil?
    end

    def named?
      !anonymous?
    end

    def name
      @name || :default
    end

    def ===(*args, &bl)
      native.===(*args, &bl)
    end

    def ==(other)
      super || (other.is_a?(Constraint) && native==other.native)
    end
    alias :eql? :==

    def hash
      self.class.hash ^ native.hash
    end

  end # class Constraint
end # module Finitio

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
finitio-0.12.0 lib/finitio/support/constraint.rb
finitio-0.11.4 lib/finitio/support/constraint.rb
finitio-0.11.3 lib/finitio/support/constraint.rb
finitio-0.11.2 lib/finitio/support/constraint.rb
finitio-0.11.1 lib/finitio/support/constraint.rb
finitio-0.10.0 lib/finitio/support/constraint.rb
finitio-0.9.1 lib/finitio/support/constraint.rb
finitio-0.9.0 lib/finitio/support/constraint.rb
finitio-0.8.0 lib/finitio/support/constraint.rb
finitio-0.7.0 lib/finitio/support/constraint.rb
finitio-0.7.0.pre.rc4 lib/finitio/support/constraint.rb
finitio-0.7.0.pre.rc3 lib/finitio/support/constraint.rb
finitio-0.7.0.pre.rc2 lib/finitio/support/constraint.rb
finitio-0.7.0.pre.rc1 lib/finitio/support/constraint.rb
finitio-0.6.1 lib/finitio/support/constraint.rb
finitio-0.6.0 lib/finitio/support/constraint.rb
finitio-0.5.2 lib/finitio/support/constraint.rb
finitio-0.5.1 lib/finitio/support/constraint.rb
finitio-0.5.0 lib/finitio/support/constraint.rb