Class: Gaku::ContactUpdation

Inherits:
Object
  • Object
show all
Defined in:
app/services/gaku/contact_updation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contact) ⇒ ContactUpdation

Returns a new instance of ContactUpdation.



5
6
7
8
# File 'app/services/gaku/contact_updation.rb', line 5

def initialize(contact)
  @contact = contact
  @errors  = []
end

Instance Attribute Details

#contactObject (readonly)

Returns the value of attribute contact.



3
4
5
# File 'app/services/gaku/contact_updation.rb', line 3

def contact
  @contact
end

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'app/services/gaku/contact_updation.rb', line 3

def errors
  @errors
end

Instance Method Details

#update(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/gaku/contact_updation.rb', line 10

def update(params)
  @contact.assign_attributes(params)

  if @contact.save
    if @contact.contactable.respond_to?(:contacts)
      remove_other_primary
      # update_primary_contact_field
    end
    true
  else
    @errors = @contact.errors
    false
  end
end