Class: ExternalServices::Service

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/external_services/service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.to_symObject



13
14
15
# File 'app/models/external_services/service.rb', line 13

def self.to_sym
  to_s.demodulize.underscore.to_sym
end

Instance Method Details

#api_nameObject



32
33
34
# File 'app/models/external_services/service.rb', line 32

def api_name
  self.class.to_sym
end

#on_subject_create(subj) ⇒ Object



17
18
19
20
# File 'app/models/external_services/service.rb', line 17

def on_subject_create(subj)
  method = subj.send("#{api_name}_id").present? ? :put : :post
  subj.send("#{api_name}_api_action", method)
end

#on_subject_destroy(subj) ⇒ Object



28
29
30
# File 'app/models/external_services/service.rb', line 28

def on_subject_destroy(subj)
  subj.send("#{api_name}_api_action", :delete)
end

#on_subject_update(subj) ⇒ Object



22
23
24
25
26
# File 'app/models/external_services/service.rb', line 22

def on_subject_update(subj)
  method = subj.send("#{api_name}_id").present? ? :put : :post
  return true if (subj.respond_to?(:became_archived?) && subj.became_archived?) && method == :post
  subj.send("#{api_name}_api_action", method)
end