Module: SocMed::Concerns::SocMedHelper

Extended by:
ActiveSupport::Concern
Included in:
Block, Follow, Like, Report
Defined in:
app/models/soc_med/concerns/soc_med_helper.rb

Instance Method Summary collapse

Instance Method Details

#raise_already_implemented_error_if_requiredObject



22
23
24
25
26
27
# File 'app/models/soc_med/concerns/soc_med_helper.rb', line 22

def raise_already_implemented_error_if_required
  klass = self.class.to_s.underscore.split('/').last
  if owner.send("#{klass}able_objects").exists?(target: target)
    raise "SocMed::#{klass.plurlarize.titleize}::AlreadyExistsError" "#{owner_type} has already liked that #{target_type}"
  end
end

#raise_not_implemented_errorObject



16
17
18
19
20
# File 'app/models/soc_med/concerns/soc_med_helper.rb', line 16

def raise_not_implemented_error
  unless target.respond_to?("number_of_#{self.class.to_s.underscore.split('/')[-1].pluralize}")
    raise NotImplementedError
  end
end

#update_count(attribute, operator) ⇒ Object



29
30
31
32
33
# File 'app/models/soc_med/concerns/soc_med_helper.rb', line 29

def update_count(attribute, operator)
  count = target.send(attribute).send(operator, 1)

  target.update("#{attribute}" => count)
end