Class: NRSER::Types::Responds
Overview
Type that encodes messages mapped to result types that member values must satisfy.
Instance Method Summary collapse
- #default_name ⇒ Object
-
#initialize(map, public: true, **options) ⇒ Responds
constructor
Instantiate a new ‘Responds`.
- #test(value) ⇒ return_type
Methods inherited from Type
#check, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #name, #respond_to?, short_name, #to_data, #to_s
Constructor Details
#initialize(map, public: true, **options) ⇒ Responds
Instantiate a new ‘Responds`.
25 26 27 28 29 30 31 |
# File 'lib/nrser/types/responds.rb', line 25 def initialize map, public: true, ** @map = NRSER.map_values(map) { |args, type| NRSER::Types.make type } end |
Instance Method Details
#default_name ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/nrser/types/responds.rb', line 38 def default_name attrs_str = @map.map { |args, type| args_str = args[1..-1].map(&:inspect).join ', ' "#{ args[0] }(#{ args_str })=#{ type.name }" }.join(', ') "#{ self.class.short_name } #{ attrs_str }" end |
#test(value) ⇒ return_type
TODO:
Document test method.
Returns @todo Document return value.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nrser/types/responds.rb', line 56 def test value @map.all? { |args, type| response = if @public value.public_send *args else value.send *args end type.test response } end |