Sha256: 631b9b13e4bd9ce044b35e0349eea5223b593f85f23036719540681cade16ad1
Contents?: true
Size: 1.22 KB
Versions: 18
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true # Mixin for lib-specific Type functions module LedgerSync module Type module ValueMixin def self.included(base) base.include SimplySerializable::Mixin end def assert_valid(args = {}) return if valid?(args) value = args.fetch(:value) raise Error::TypeError::ValueClassError.new( expected: valid_classes, given: value.class ) end # Do not override this method. Override private method cast_value def cast(args = {}) assert_valid(args) return nil if args.fetch(:value).nil? cast_value(args) end def valid?(args = {}) valid_class?(args) end private # Override this method to handle different types of casting. def cast_value(args = {}) value = args.fetch(:value) super(value) end def valid_class?(args = {}) value = args.fetch(:value) return true if value.nil? return true if valid_classes.select { |e| value.is_a?(e) }.any? false end def valid_classes [ Object ] end # def cast? # false # end end end end
Version data entries
18 entries across 18 versions & 1 rubygems