class Acfs::Service
User {Acfs::Service} to define your services. That includes an identity used to identify the service in configuration files and middlewares the service uses.
Configure your service URLs in a YAML file loaded in an initializer using the identity as a key:
production: services: user_service_key: "http://users.service.org/base/path"
@example
class UserService < Acfs::Service identity :user_service_key use Acfs::Middleware::MessagePackDecoder end
Attributes
options[RW]
Public Class Methods
base_url()
click to toggle source
@api private @return [String]
# File lib/acfs/service.rb, line 82 def base_url unless (base = Acfs::Configuration.current.locate identity) raise ArgumentError.new \ "#{identity} not configured. Add `locate '" \ "#{identity.to_s.underscore}', 'http://service.url/'` " \ 'to your configuration.' end base.to_s end
identity(identity = nil)
click to toggle source
@api public
@overload identity()
Return configured identity key or derive key from class name. @return [Symbol] Service identity key.
@overload identity(identity)
Set identity key. @param [#to_s] identity New identity key. @return [Symbol] New set identity key.
# File lib/acfs/service.rb, line 74 def identity(identity = nil) @identity = identity.to_s.to_sym unless identity.nil? @identity ||= name.to_sym end
new(**options)
click to toggle source
@api private
# File lib/acfs/service.rb, line 31 def initialize(**options) @options = options end
Public Instance Methods
location(resource_class, path: nil, action: :list, **)
click to toggle source
@api private @return [Location]
# File lib/acfs/service.rb, line 38 def location(resource_class, path: nil, action: :list, **) path ||= options[:path] if path.is_a?(Hash) && path.key?(action) path = path.fetch(action) else path = path.is_a?(Hash) ? path[:all].to_s : path.to_s if path.blank? path = (resource_class.name || 'class').pluralize.underscore end path = resource_class.location_default_path(action, path.strip) end if path.nil? raise ArgumentError.new "Location for `#{action}' explicit disabled by set to nil." end Location.new [self.class.base_url.to_s, path.to_s].join('/') end