Class: Natsuzora::Contract::TypeDef

Inherits:
Object
  • Object
show all
Defined in:
lib/natsuzora/contract/type_def.rb

Overview

A type definition with optional diff marker.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contract, marker: nil) ⇒ TypeDef

Returns a new instance of TypeDef.



12
13
14
15
# File 'lib/natsuzora/contract/type_def.rb', line 12

def initialize(contract, marker: nil)
  @marker = marker
  @contract = contract
end

Instance Attribute Details

#contractObject (readonly)

Returns the value of attribute contract.



10
11
12
# File 'lib/natsuzora/contract/type_def.rb', line 10

def contract
  @contract
end

#markerObject (readonly)

Returns the value of attribute marker.



10
11
12
# File 'lib/natsuzora/contract/type_def.rb', line 10

def marker
  @marker
end

Instance Method Details

#available?(target) ⇒ Boolean

Check if this type is available for the specified target. NOTE: Diff resolution table here mirrors Field#for_target — keep in sync.

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/natsuzora/contract/type_def.rb', line 19

def available?(target)
  # rubocop:disable Lint/DuplicateBranch
  case [@marker, target]
  in [nil, _]
    true
  in [DiffMarker::ADDED, ValidationTarget::CURRENT]
    false
  in [DiffMarker::ADDED, ValidationTarget::NEXT]
    true
  in [DiffMarker::REMOVED, ValidationTarget::CURRENT]
    true
  in [DiffMarker::REMOVED, ValidationTarget::NEXT]
    false
  in [DiffMarker::CHANGED, _]
    false # Changed not allowed for type defs
  end
  # rubocop:enable Lint/DuplicateBranch
end