Module: SoberSwag::Reporting::Output::Interface
Overview
Interface methods for all outputs.
Instance Method Summary collapse
- #call!(item) ⇒ Object
- #described(description) ⇒ Object
- #enum(*cases) ⇒ SoberSwag::Reporting::Output::Enum
-
#in_range(range) ⇒ SoberSwag::Reporting::Output::InRange
Constrained values: must be within the given range.
- #list ⇒ Object (also: #array)
- #nilable ⇒ Object
-
#partitioned(other, &block) ⇒ Interface
Partition this serializer into two potentials.
- #referenced(name) ⇒ Object
-
#reporting? ⇒ Boolean
Show off that this is a reporting output.
-
#serialize(item) ⇒ Object
Delegates to #call.
- #via_map(&block) ⇒ Object
Instance Method Details
#call!(item) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 7 def call!(item) res = serialize_report(item) raise Report::Error.new(res) if res.is_a?(Report::Base) # rubocop:disable Style/RaiseArgs res end |
#described(description) ⇒ Object
90 91 92 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 90 def described(description) Described.new(self, description) end |
#enum(*cases) ⇒ SoberSwag::Reporting::Output::Enum
35 36 37 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 35 def enum(*cases) Enum.new(self, cases) end |
#in_range(range) ⇒ SoberSwag::Reporting::Output::InRange
Constrained values: must be within the given range.
46 47 48 49 50 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 46 def in_range(range) raise ArgumentError, 'need a range' unless range.is_a?(Range) InRange.new(self, range) end |
#list ⇒ Object Also known as: array
52 53 54 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 52 def list List.new(self) end |
#nilable ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 82 def nilable Partitioned.new( :nil?.to_proc, Null.new, self ) end |
#partitioned(other, &block) ⇒ Interface
Partition this serializer into two potentials.
If the block given returns false, we will use other as the serializer.
Otherwise, we will use self.
This might be useful to serialize a sum type:
ResolutionOutput = TransferOutput.partitioned(RefundOutput) { |to_serialize| to_serialize.is_a?(Transfer)
72 73 74 75 76 77 78 79 80 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 72 def partitioned(other, &block) raise ArgumentError, 'need a block' if block.nil? Partitioned.new( block, self, other ) end |
#referenced(name) ⇒ Object
39 40 41 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 39 def referenced(name) Referenced.new(self, name) end |
#reporting? ⇒ Boolean
Show off that this is a reporting output.
17 18 19 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 17 def reporting? true end |
#serialize(item) ⇒ Object
Delegates to #call
23 24 25 |
# File 'lib/sober_swag/reporting/output/interface.rb', line 23 def serialize(item) call(item) end |