Class: LedgerSync::Type::ReferenceMany
- Includes:
- ValueMixin
- Defined in:
- lib/ledger_sync/type/reference_many.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
Instance Method Summary collapse
- #cast(args = {}) ⇒ Object
-
#initialize(resource_class:) ⇒ ReferenceMany
constructor
A new instance of ReferenceMany.
- #type ⇒ Object
- #valid?(args = {}) ⇒ Boolean
Methods included from ValueMixin
Constructor Details
#initialize(resource_class:) ⇒ ReferenceMany
Returns a new instance of ReferenceMany.
12 13 14 15 |
# File 'lib/ledger_sync/type/reference_many.rb', line 12 def initialize(resource_class:) @resource_class = resource_class super() end |
Instance Attribute Details
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
10 11 12 |
# File 'lib/ledger_sync/type/reference_many.rb', line 10 def resource_class @resource_class end |
Instance Method Details
#cast(args = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ledger_sync/type/reference_many.rb', line 17 def cast(args = {}) value = args.fetch(:value) return if value.nil? many_array_class = LedgerSync::ResourceAttribute::Reference::Many::ManyArray return value if value.is_a?(many_array_class) unless value.is_a?(Array) raise "Cannot convert #{value.class} to LedgerSync::ResourceAttribute::Reference::Many::ManyArray" end many_array_class.new(value) end |
#type ⇒ Object
31 32 33 |
# File 'lib/ledger_sync/type/reference_many.rb', line 31 def type :reference_many end |
#valid?(args = {}) ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/ledger_sync/type/reference_many.rb', line 35 def valid?(args = {}) value = args.fetch(:value) return false unless value.is_a?(Array) return true if (resource_classes & value.map(&:class)).any? return true if value.is_a?(Array) && value.empty? false end |