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



10
11
12
# File 'app/models/external_services/service.rb', line 10

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

Instance Method Details

#api_nameObject



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

def api_name
  self.class.to_sym
end

#on_subject_create(subj) ⇒ Object



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

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



25
26
27
# File 'app/models/external_services/service.rb', line 25

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

#on_subject_update(subj) ⇒ Object



19
20
21
22
23
# File 'app/models/external_services/service.rb', line 19

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