Class: Address::Creator
- Inherits:
-
BaseService
- Object
- BaseService
- Address::Creator
- Defined in:
- app/services/address/creator.rb
Overview
Service object: creator.
Defined Under Namespace
Classes: Result
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
- #initialize(options = {}) ⇒ void constructor
-
#process(attributes, context_object = nil) ⇒ Result
Creates an address, optionally nested under a context object's addresses, and records the party timezone on success.
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger
Constructor Details
#initialize(options = {}) ⇒ void
21 22 23 |
# File 'app/services/address/creator.rb', line 21 def initialize( = {}) @party_timezone_recorder = [:party_timezone_recorder] || PartyRecordTimezone.new end |
Instance Method Details
#process(attributes, context_object = nil) ⇒ Result
Creates an address, optionally nested under a context object's addresses,
and records the party timezone on success.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/services/address/creator.rb', line 30 def process(attributes, context_object = nil) = [] address = context_object.nil? ? Address.new(attributes) : context_object.addresses.new(attributes) address.check_for_duplicates = true if address.save @party_timezone_recorder.process(address.party) if address.party Result.new(saved: true, autocorrect_message: address., messages: , address: address) else Result.new(saved: false, autocorrect_message: address., messages: address.errors., address: address) end end |