Class: Gaku::ContactCreation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contactObject (readonly)

Returns the value of attribute contact.



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

def contact
  @contact
end

#errorsObject (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

#saveObject



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