Class: LedgerSync::ResourceAttribute
- Inherits:
-
Object
- Object
- LedgerSync::ResourceAttribute
- Includes:
- Fingerprintable::Mixin, SimplySerializable::Mixin
- Defined in:
- lib/ledger_sync/resource_attribute.rb,
lib/ledger_sync/resource_attribute/mixin.rb,
lib/ledger_sync/resource_attribute/reference.rb,
lib/ledger_sync/resource_attribute/dirty_mixin.rb,
lib/ledger_sync/resource_attribute/reference/one.rb,
lib/ledger_sync/resource_attribute/reference/many.rb
Direct Known Subclasses
Defined Under Namespace
Modules: DirtyMixin, Mixin Classes: Reference
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #cast(value) ⇒ Object
-
#initialize(name:, type:, value: nil) ⇒ ResourceAttribute
constructor
A new instance of ResourceAttribute.
-
#reference? ⇒ Boolean
This is for ActiveModel::Dirty, since we define @attributes def forgetting_assignment; end.
- #references_many? ⇒ Boolean
- #valid_with?(value:) ⇒ Boolean
Constructor Details
#initialize(name:, type:, value: nil) ⇒ ResourceAttribute
Returns a new instance of ResourceAttribute.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ledger_sync/resource_attribute.rb', line 23 def initialize(name:, type:, value: nil) @name = name.to_sym type = type.new if type.respond_to?(:new) && !type.is_a?(Type::Value) raise "Invalid Type: #{type}" unless type.is_a?(ActiveModel::Type::Value) @type = type @value = value end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/ledger_sync/resource_attribute.rb', line 19 def name @name end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
19 20 21 |
# File 'lib/ledger_sync/resource_attribute.rb', line 19 def reference @reference end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/ledger_sync/resource_attribute.rb', line 19 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
18 19 20 |
# File 'lib/ledger_sync/resource_attribute.rb', line 18 def value @value end |
Instance Method Details
#cast(value) ⇒ Object
35 36 37 |
# File 'lib/ledger_sync/resource_attribute.rb', line 35 def cast(value) type.cast(value) end |
#reference? ⇒ Boolean
This is for ActiveModel::Dirty, since we define @attributes def forgetting_assignment; end
42 43 44 |
# File 'lib/ledger_sync/resource_attribute.rb', line 42 def reference? is_a?(Reference) end |
#references_many? ⇒ Boolean
46 47 48 |
# File 'lib/ledger_sync/resource_attribute.rb', line 46 def references_many? is_a?(Reference::Many) end |
#valid_with?(value:) ⇒ Boolean
50 51 52 |
# File 'lib/ledger_sync/resource_attribute.rb', line 50 def valid_with?(value:) type.valid_without_casting?(value: value) end |