Class: Modulorails::BaseService

Inherits:
Object
  • Object
show all
Defined in:
lib/modulorails/services/base_service.rb

Overview

The base class for services. Should be implemented by ApplicationService following the model of ActiveRecord::Base and ApplicationRecord.

Direct Known Subclasses

LogsForMethodService

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(*args, **kwargs, &block) ⇒ Object



8
9
10
# File 'lib/modulorails/services/base_service.rb', line 8

def self.call(*args, &block)
  new(*args, &block).call
end

.pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale) ⇒ Object

Shamelessly copied from text_helper



32
33
34
35
36
37
38
39
40
# File 'lib/modulorails/services/base_service.rb', line 32

def self.pluralize(count, singular, plural_arg=nil, plural: plural_arg, locale: I18n.locale)
  word = if count == 1 || count =~ /^1(\.0+)?$/
           singular
         else
           plural || singular.pluralize(locale)
         end

  "#{count || 0} #{word}"
end

Instance Method Details

#callObject

This method is abstract.

The main method to implement for your service to do something

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/modulorails/services/base_service.rb', line 18

def call
  raise NotImplementedError.new('Implement method call on sub-class')
end

#to_sObject



22
23
24
# File 'lib/modulorails/services/base_service.rb', line 22

def to_s
  self.class.to_s
end

#to_tagObject

The method used by Modulorails::LogsForMethodService to log the service name



27
28
29
# File 'lib/modulorails/services/base_service.rb', line 27

def to_tag
  self.class.to_s
end