class NRSER::Types::IsA
Type
satisfied by class membership (or mixin presence for modules).
Tests via the subject value's `#is_a?` method is `true` for {#mod}. Works for class instances as will as mixins.
@note
Construct {IsA} types using the {.IsA} factory.
Attributes
mod[R]
Public Class Methods
new(mod, init_from_data: false, **options)
click to toggle source
Calls superclass method
NRSER::Types::Type::new
# File lib/nrser/types/is_a.rb, line 35 def initialize mod, init_from_data: false, **options unless mod.is_a?( Module ) raise ArgumentError, "`mod` argument must be a Module (inc. Class), " \ "received #{ mod.inspect }" end super **options @init_from_data = !!init_from_data @mod = mod end
Public Instance Methods
==(other)
click to toggle source
# File lib/nrser/types/is_a.rb, line 93 def == other equal?( other ) || ( self.class == other.class && self.mod == other.mod ) end
custom_from_data(data)
click to toggle source
Forwards to `mod.from_data`.
@param data (see NRSER::Types::Type#from_data
) @return (see NRSER::Types::Type#from_data
) @raise (see NRSER::Types::Type#from_data
)
# File lib/nrser/types/is_a.rb, line 71 def custom_from_data data if init_from_data? mod.new data else mod.from_data data end end
explain()
click to toggle source
# File lib/nrser/types/is_a.rb, line 50 def explain mod.safe_name end
has_from_data?()
click to toggle source
Overrides {NRSER::Types::Type#has_from_data?} to respond `true` when there is a instance-specific `@from_data` or the {#mod} responds to `.from_data`.
@return [Boolean]
# File lib/nrser/types/is_a.rb, line 86 def has_from_data? @from_data || init_from_data? || mod.respond_to?( :from_data ) end
init_from_data?()
click to toggle source
# File lib/nrser/types/is_a.rb, line 60 def init_from_data? @init_from_data end
test?(value)
click to toggle source
# File lib/nrser/types/is_a.rb, line 55 def test? value value.is_a? mod end