Class: LedgerSync::Type::ReferenceOne
- Includes:
- ValueMixin
- Defined in:
- lib/ledger_sync/type/reference_one.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
Instance Method Summary collapse
- #error_message(args = {}) ⇒ Object
-
#initialize(resource_class:) ⇒ ReferenceOne
constructor
A new instance of ReferenceOne.
- #type ⇒ Object
- #valid_without_casting?(value:) ⇒ Boolean
Methods included from ValueMixin
#cast?, included, #valid_classes
Constructor Details
#initialize(resource_class:) ⇒ ReferenceOne
Returns a new instance of ReferenceOne.
10 11 12 13 |
# File 'lib/ledger_sync/type/reference_one.rb', line 10 def initialize(resource_class:) @resource_class = resource_class super() end |
Instance Attribute Details
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
8 9 10 |
# File 'lib/ledger_sync/type/reference_one.rb', line 8 def resource_class @resource_class end |
Instance Method Details
#error_message(args = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ledger_sync/type/reference_one.rb', line 15 def (args = {}) attribute = args.fetch(:attribute) resource_class = args.fetch(:resource_class) value = args.fetch(:value) if @resource_class.is_a?(Array) "Attribute #{attribute.name} for #{resource_class.name} should be one of the following: #{@resource_class.map(&:name).join(', ')}. Given #{value.class.name}" else "Attribute #{attribute.name} for #{resource_class.name} should be a #{@resource_class.name}. Given #{value.class.name}" end end |
#type ⇒ Object
27 28 29 |
# File 'lib/ledger_sync/type/reference_one.rb', line 27 def type :reference_one end |
#valid_without_casting?(value:) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/ledger_sync/type/reference_one.rb', line 31 def valid_without_casting?(value:) return true if value.nil? return true if resource_classes.select { |e| value.is_a?(e) }.any? false end |