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, opts = {}) ⇒ 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( = {}) = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
25 26 27 |
# File 'lib/acfs/service.rb', line 25 def 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.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/acfs/service.rb', line 90 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
82 83 84 85 |
# File 'lib/acfs/service.rb', line 82 def identity(identity = nil) @identity = identity.to_s.to_sym unless identity.nil? @identity ||= name.to_sym end |
Instance Method Details
#location(resource_class, opts = {}) ⇒ 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 59 60 61 62 63 64 65 66 |
# File 'lib/acfs/service.rb', line 38 def location(resource_class, opts = {}) opts.reverse_merge! action = opts[:action] || :list path = begin if opts[:path].is_a?(Hash) && opts[:path].key?(action) opts[:path].fetch(action) else path = if opts[:path].is_a?(Hash) opts[:path][:all].to_s else opts[:path].to_s end if path.blank? path = (resource_class.name || 'class').pluralize.underscore end resource_class.location_default_path(action, path.strip) end 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 |