Class: Eventually::Validation::Arity

Inherits:
Object
  • Object
show all
Defined in:
lib/eventually/validation/arity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, emitter, arity) ⇒ Arity

Returns a new instance of Arity.



6
7
8
9
10
11
# File 'lib/eventually/validation/arity.rb', line 6

def initialize(event, emitter, arity)
  @event = event
  @emitter = emitter
  @arity = @received = arity
  @expected = @emitter.class.arity_for_event(@event)
end

Instance Attribute Details

#expectedObject (readonly)

Returns the value of attribute expected.



5
6
7
# File 'lib/eventually/validation/arity.rb', line 5

def expected
  @expected
end

#receivedObject (readonly)

Returns the value of attribute received.



5
6
7
# File 'lib/eventually/validation/arity.rb', line 5

def received
  @received
end

Instance Method Details

#raise_unless_valid!Object



17
18
19
# File 'lib/eventually/validation/arity.rb', line 17

def raise_unless_valid!
  raise "Arity validation failed for event :#{@event} (expected #{@expected}, received #{@received})" unless valid?
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/eventually/validation/arity.rb', line 13

def valid?
  !@emitter.class.validates_arity?(@event) || @received == @expected
end