Class: Inflect::AbstractService
- Inherits:
-
Object
- Object
- Inflect::AbstractService
- Includes:
- Comparable, Responsive, ServiceProviderMethods, Singleton
- Defined in:
- lib/inflect/abstract_service.rb
Overview
Acts as an specification or standard required for a Service Class to be consumed by the application. A Service Class is just a wrapper for any possible service you’d like to give support to, just by having four prerequisites.
Instance Attribute Summary collapse
-
#priority ⇒ Object
readonly
In case there are modules that provide similar contents the one with most
priorityis picked. -
#words ⇒ Object
readonly
A
wordsArray constant with the keywordsof the Service.
Instance Method Summary collapse
-
#<=>(other_service) ⇒ Object
Implement Comparable in order to be sortable.
-
#actions ⇒ Object
Virtual attributes for the service actions.
-
#handle(request) ⇒ Object
Returns a Hash with retrieved data by routing from the request to the method specified by the request’s action attribute.
-
#initialize ⇒ AbstractService
constructor
A new instance of AbstractService.
-
#keyword ⇒ Object
Virtual attribute for the services keyword.
-
#valid?(request) ⇒ Boolean
Receives a Request and returns true if the service can handle the request given.
Methods included from ServiceProviderMethods
Methods included from Responsive
Constructor Details
#initialize ⇒ AbstractService
Returns a new instance of AbstractService.
25 26 27 28 |
# File 'lib/inflect/abstract_service.rb', line 25 def initialize @priority = 0 @words = [] end |
Instance Attribute Details
#priority ⇒ Object (readonly)
In case there are modules that provide similar contents the one with most priority is picked.
23 24 25 |
# File 'lib/inflect/abstract_service.rb', line 23 def priority @priority end |
#words ⇒ Object (readonly)
A words Array constant with the key words of the Service.
19 20 21 |
# File 'lib/inflect/abstract_service.rb', line 19 def words @words end |
Instance Method Details
#<=>(other_service) ⇒ Object
Implement Comparable in order to be sortable.
31 32 33 |
# File 'lib/inflect/abstract_service.rb', line 31 def <=>(other_service) priority <=> other_service.priority end |
#actions ⇒ Object
Virtual attributes for the service actions. Every action must have its matching method.
67 68 69 |
# File 'lib/inflect/abstract_service.rb', line 67 def actions words[1..-1] end |
#handle(request) ⇒ Object
Returns a Hash with retrieved data by routing from the request to the method specified by the request’s action attribute.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/inflect/abstract_service.rb', line 48 def handle(request) if action_defined(request.action) && !action_implemented(request.action) no_method_error request else if request.arguments.empty? send request.action else send request.action, request.arguments end end end |
#keyword ⇒ Object
Virtual attribute for the services keyword.
61 62 63 |
# File 'lib/inflect/abstract_service.rb', line 61 def keyword words.first end |
#valid?(request) ⇒ Boolean
Receives a Request and returns true if the service can handle the request given.
39 40 41 42 |
# File 'lib/inflect/abstract_service.rb', line 39 def valid?(request) (self.keyword.eql? request.keyword) && action_defined(request.action) end |