Module: LedgerSync::Type::ValueMixin
- Included in:
- Boolean, Date, Float, ID, Integer, ReferenceMany, ReferenceOne, String, Value
- Defined in:
- lib/ledger_sync/type/value_mixin.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cast? ⇒ Boolean
- #error_message(attribute:, resource:, value:) ⇒ Object
- #valid_classes ⇒ Object
- #valid_without_casting?(value:) ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
7 8 9 |
# File 'lib/ledger_sync/type/value_mixin.rb', line 7 def self.included(base) base.include SimplySerializable::Mixin end |
Instance Method Details
#error_message(attribute:, resource:, value:) ⇒ Object
15 16 17 |
# File 'lib/ledger_sync/type/value_mixin.rb', line 15 def (attribute:, resource:, value:) "Attribute #{attribute.name} for #{resource.class.name} should be a class supported by #{self.class.name}. Given: #{value.class}" end |
#valid_classes ⇒ Object
19 20 21 |
# File 'lib/ledger_sync/type/value_mixin.rb', line 19 def valid_classes raise NotImplementedError end |
#valid_without_casting?(value:) ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/ledger_sync/type/value_mixin.rb', line 23 def valid_without_casting?(value:) return true if value.nil? return true if valid_classes.select { |e| value.is_a?(e) }.any? false end |