Class: Modulorails::BaseService
- Inherits:
-
Object
- Object
- Modulorails::BaseService
- 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
Class Method Summary collapse
- .call(*args, **kwargs, &block) ⇒ Object
-
.pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale) ⇒ Object
Shamelessly copied from text_helper.
Instance Method Summary collapse
- #call ⇒ Object abstract
- #to_s ⇒ Object
-
#to_tag ⇒ Object
The method used by Modulorails::LogsForMethodService to log the service name.
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
#call ⇒ Object
This method is abstract.
The main method to implement for your service to do something
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_s ⇒ Object
22 23 24 |
# File 'lib/modulorails/services/base_service.rb', line 22 def to_s self.class.to_s end |
#to_tag ⇒ Object
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 |