module Vidibus::Service::Mongoid::ClassMethods
Public Instance Methods
connector()
click to toggle source
Returns Connector service, if it has been configured, or raises an ConfigurationError
.
# File lib/vidibus/service/mongoid.rb, line 85 def connector where(:function => "connector").and(:realm_uuid => nil).first or raise ConfigurationError.new("No Connector has been assigned to this service yet. Use your Connector to perform the assignment.") end
discover(wanted, realm = nil)
click to toggle source
Returns best service by function or UUID within given realm. If a service can be found in stored, it will be fetched from Connector.
# File lib/vidibus/service/mongoid.rb, line 92 def discover(wanted, realm = nil) local(wanted, realm) || remote(wanted, realm) end
local(wanted, realm = nil)
click to toggle source
Returns stored service by function or UUID within given realm.
# File lib/vidibus/service/mongoid.rb, line 97 def local(wanted, realm = nil) key = Vidibus::Uuid.validate(wanted) ? :uuid : :function where(key => wanted).and(:realm_uuid => realm).first end
remote(wanted, realm)
click to toggle source
Requests service from Connector and stores it. Wanted may be a function or an UUID. This method should not be called directly. Use discover
to avoid unneccessary lookups.
# File lib/vidibus/service/mongoid.rb, line 105 def remote(wanted, realm) unless realm fail(ArgumentError, 'Please provide a valid realm to discover an appropriate service.') end response = connector.client. get("/services/#{wanted}", :query => {:realm => realm}) if response secret = response["secret"] unless secret fail(ConnectorError, "The Connector did not return a secret for #{wanted}. Response was: #{response.parsed_response.inspect}") end secret = Vidibus::Secure.decrypt(secret, this.secret) attributes = response.only(%w[uuid function url]). merge(:realm_uuid => realm, :secret => secret) create!(attributes) else fail('no service found') end end
this()
click to toggle source
Returns this service, if it has been configured, or raises an ConfigurationError
.
# File lib/vidibus/service/mongoid.rb, line 79 def this where(:this => true).and(:realm_uuid => nil).first or raise ConfigurationError.new("This service has not been configured yet. Use your Connector to set it up.") end