Module: Axn::Core::ContractForSubfields
- Defined in:
- lib/axn/core/contract_for_subfields.rb
Defined Under Namespace
Modules: ClassMethods Classes: SubfieldConfig
Class Method Summary collapse
- .included(base) ⇒ Object
-
.resolve_parent(source, on) ⇒ Object
Resolves the parent value an ‘on:` points at.
Class Method Details
.included(base) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/axn/core/contract_for_subfields.rb', line 12 def self.included(base) base.class_eval do class_attribute :subfield_configs, default: [] extend ClassMethods end end |
.resolve_parent(source, on) ⇒ Object
Resolves the parent value an ‘on:` points at. `on:` may be a single field/subfield (e.g. :address) or a dotted path (e.g. “address.billing”) — the root segment is read via its reader and any remaining segments are dug out via the Extract resolver. Shared by the subfield reader and the inbound validation runner so both treat paths identically.
24 25 26 27 28 29 30 |
# File 'lib/axn/core/contract_for_subfields.rb', line 24 def self.resolve_parent(source, on) root, *rest = on.to_s.split(".") value = source.public_send(root) return value if rest.empty? Axn::Core::FieldResolvers.resolve(type: :extract, field: rest.join("."), provided_data: value) end |