Class: Natsuzora::Contract::Field
- Inherits:
-
Object
- Object
- Natsuzora::Contract::Field
- Defined in:
- lib/natsuzora/contract/field.rb
Overview
A field with optional diff marker and type change information.
Instance Attribute Summary collapse
-
#current_type ⇒ Object
readonly
Returns the value of attribute current_type.
-
#marker ⇒ Object
readonly
Returns the value of attribute marker.
-
#next_type ⇒ Object
readonly
Returns the value of attribute next_type.
Class Method Summary collapse
-
.added(contract) ⇒ Object
Create an added field (+).
-
.changed(current, next_type) ⇒ Object
Create a changed field (*).
-
.new_plain(contract) ⇒ Object
Create a field without diff marker.
-
.removed(contract) ⇒ Object
Create a removed field (-).
Instance Method Summary collapse
-
#for_target(target) ⇒ Object
Get the contract for the specified target generation.
-
#initialize(current_type, marker: nil, next_type: nil) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(current_type, marker: nil, next_type: nil) ⇒ Field
Returns a new instance of Field.
12 13 14 15 16 |
# File 'lib/natsuzora/contract/field.rb', line 12 def initialize(current_type, marker: nil, next_type: nil) @marker = marker @current_type = current_type @next_type = next_type end |
Instance Attribute Details
#current_type ⇒ Object (readonly)
Returns the value of attribute current_type.
10 11 12 |
# File 'lib/natsuzora/contract/field.rb', line 10 def current_type @current_type end |
#marker ⇒ Object (readonly)
Returns the value of attribute marker.
10 11 12 |
# File 'lib/natsuzora/contract/field.rb', line 10 def marker @marker end |
#next_type ⇒ Object (readonly)
Returns the value of attribute next_type.
10 11 12 |
# File 'lib/natsuzora/contract/field.rb', line 10 def next_type @next_type end |
Class Method Details
.added(contract) ⇒ Object
Create an added field (+).
24 25 26 |
# File 'lib/natsuzora/contract/field.rb', line 24 def self.added(contract) new(contract, marker: DiffMarker::ADDED) end |
.changed(current, next_type) ⇒ Object
Create a changed field (*).
34 35 36 |
# File 'lib/natsuzora/contract/field.rb', line 34 def self.changed(current, next_type) new(current, marker: DiffMarker::CHANGED, next_type: next_type) end |
.new_plain(contract) ⇒ Object
Create a field without diff marker.
19 20 21 |
# File 'lib/natsuzora/contract/field.rb', line 19 def self.new_plain(contract) new(contract) end |
.removed(contract) ⇒ Object
Create a removed field (-).
29 30 31 |
# File 'lib/natsuzora/contract/field.rb', line 29 def self.removed(contract) new(contract, marker: DiffMarker::REMOVED) end |
Instance Method Details
#for_target(target) ⇒ Object
Get the contract for the specified target generation. NOTE: Diff resolution table here mirrors TypeDef#available? — keep in sync.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/natsuzora/contract/field.rb', line 40 def for_target(target) # rubocop:disable Lint/DuplicateBranch case [@marker, target] in [nil, _] @current_type in [DiffMarker::ADDED, ValidationTarget::CURRENT] nil in [DiffMarker::ADDED, ValidationTarget::NEXT] @current_type in [DiffMarker::REMOVED, ValidationTarget::CURRENT] @current_type in [DiffMarker::REMOVED, ValidationTarget::NEXT] nil in [DiffMarker::CHANGED, ValidationTarget::CURRENT] @current_type in [DiffMarker::CHANGED, ValidationTarget::NEXT] @next_type end # rubocop:enable Lint/DuplicateBranch end |