Class: Acfs::Service
- Inherits:
-
Object
- Object
- Acfs::Service
- Includes:
- Middleware
- Defined in:
- lib/acfs/service.rb,
lib/acfs/service/middleware.rb,
lib/acfs/service/middleware/stack.rb
Overview
User 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"
Defined Under Namespace
Modules: Middleware
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(**options) ⇒ Service
constructor
private
A new instance of Service.
- #location(resource_class, path: nil, action: :list) ⇒ Location private
Methods included from Middleware
Constructor Details
#initialize(**options) ⇒ Service
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Service.
31 32 33 |
# File 'lib/acfs/service.rb', line 31 def initialize(**) @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
25 26 27 |
# File 'lib/acfs/service.rb', line 25 def @options end |
Class Method Details
.base_url ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Symbol .identity(identity) ⇒ Symbol
74 75 76 77 |
# 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 |
Instance Method Details
#location(resource_class, path: nil, action: :list) ⇒ Location
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/acfs/service.rb', line 38 def location(resource_class, path: nil, action: :list, **) path ||= [: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 |