Class: Solid::Result::Handler::AllowedTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/solid/result/handler/allowed_types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_checker) ⇒ AllowedTypes

Returns a new instance of AllowedTypes.



8
9
10
11
12
13
14
# File 'lib/solid/result/handler/allowed_types.rb', line 8

def initialize(type_checker)
  @type_checker = type_checker

  @expectations = type_checker.expectations

  @unchecked = @expectations.allowed_types.dup
end

Instance Attribute Details

#type_checkerObject (readonly)

Returns the value of attribute type_checker.



6
7
8
# File 'lib/solid/result/handler/allowed_types.rb', line 6

def type_checker
  @type_checker
end

#uncheckedObject (readonly)

Returns the value of attribute unchecked.



6
7
8
# File 'lib/solid/result/handler/allowed_types.rb', line 6

def unchecked
  @unchecked
end

Instance Method Details

#all_checked?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/solid/result/handler/allowed_types.rb', line 32

def all_checked?
  unchecked.empty?
end

#allow?(types) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/solid/result/handler/allowed_types.rb', line 16

def allow?(types)
  check!(types, type_checker.allow?(types))
end

#allow_failure?(types) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/solid/result/handler/allowed_types.rb', line 26

def allow_failure?(types)
  unchecked.subtract(@expectations.failure.allowed_types) if types.empty?

  check!(types, type_checker.allow_failure?(types))
end

#allow_success?(types) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/solid/result/handler/allowed_types.rb', line 20

def allow_success?(types)
  unchecked.subtract(@expectations.success.allowed_types) if types.empty?

  check!(types, type_checker.allow_success?(types))
end