Class: Gaku::ContactCreation
- Inherits:
-
Object
- Object
- Gaku::ContactCreation
- Defined in:
- app/services/gaku/contact_creation.rb
Instance Attribute Summary collapse
-
#contact ⇒ Object
readonly
Returns the value of attribute contact.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ ContactCreation
constructor
A new instance of ContactCreation.
- #save ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ ContactCreation
Returns a new instance of ContactCreation.
5 6 7 8 |
# File 'app/services/gaku/contact_creation.rb', line 5 def initialize(params = {}) @contact = Contact.new(params) @errors = [] end |
Instance Attribute Details
#contact ⇒ Object (readonly)
Returns the value of attribute contact.
3 4 5 |
# File 'app/services/gaku/contact_creation.rb', line 3 def contact @contact end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'app/services/gaku/contact_creation.rb', line 3 def errors @errors end |
Instance Method Details
#save ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/gaku/contact_creation.rb', line 10 def save ensure_first_is_primary if @contact.save if @contact.contactable.respond_to?(:contacts) remove_other_primary end return true else @errors = @contact.errors return false end end |
#save! ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/services/gaku/contact_creation.rb', line 24 def save! if save return @contact else fail 'Failed to save record' end end |