Class: Finitio::Constraint

Inherits:
Object
  • Object
show all
Includes:
Metadata
Defined in:
lib/finitio/support/constraint.rb

Constant Summary

Constants included from Metadata

Metadata::EMPTY_METADATA

Instance Method Summary collapse

Methods included from Metadata

#metadata, #metadata=, #metadata?

Constructor Details

#initialize(native, name = nil, metadata = nil) ⇒ Constraint

Returns a new instance of Constraint.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/finitio/support/constraint.rb', line 5

def initialize(native, name = nil,  = 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 = 
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



36
37
38
# File 'lib/finitio/support/constraint.rb', line 36

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

#===(*args, &bl) ⇒ Object



32
33
34
# File 'lib/finitio/support/constraint.rb', line 32

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

#anonymous?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/finitio/support/constraint.rb', line 20

def anonymous?
  @name.nil?
end

#hashObject



41
42
43
# File 'lib/finitio/support/constraint.rb', line 41

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

#nameObject



28
29
30
# File 'lib/finitio/support/constraint.rb', line 28

def name
  @name || :default
end

#named?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/finitio/support/constraint.rb', line 24

def named?
  !anonymous?
end