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

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

#cast?Boolean

Returns:



11
12
13
# File 'lib/ledger_sync/type/value_mixin.rb', line 11

def cast?
  false
end

#error_message(attribute:, resource:, value:) ⇒ Object



15
16
17
# File 'lib/ledger_sync/type/value_mixin.rb', line 15

def error_message(attribute:, resource:, value:)
  "Attribute #{attribute.name} for #{resource.class.name} should be a class supported by #{self.class.name}.  Given: #{value.class}"
end

#valid_classesObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/ledger_sync/type/value_mixin.rb', line 19

def valid_classes
  raise NotImplementedError
end

#valid_without_casting?(value:) ⇒ Boolean

Returns:



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