Module: LedgerSync::Type::ValueMixin

Included in:
Boolean, Date, Float, Hash, 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

#assert_valid(args = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/ledger_sync/type/value_mixin.rb', line 11

def assert_valid(args = {})
  return if valid?(args)

  value = args.fetch(:value)

  raise Error::TypeError::ValueClassError.new(
    expected: valid_classes,
    given: value.class
  )
end

#cast(args = {}) ⇒ Object

Do not override this method. Override private method cast_value



23
24
25
26
27
28
# File 'lib/ledger_sync/type/value_mixin.rb', line 23

def cast(args = {})
  assert_valid(args)
  return nil if args.fetch(:value).nil?

  cast_value(args)
end

#valid?(args = {}) ⇒ Boolean

Returns:



30
31
32
# File 'lib/ledger_sync/type/value_mixin.rb', line 30

def valid?(args = {})
  valid_class?(args)
end