Module: Jerakia::Scope::Server

Defined in:
lib/jerakia/scope/server.rb

Defined Under Namespace

Classes: Database

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(realm, identifier) ⇒ Object


42
43
44
# File 'lib/jerakia/scope/server.rb', line 42

def find(realm, identifier)
  Database::Resource.first(:identifier => identifier, :realm => realm)
end

.store(realm, identifier, scope) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jerakia/scope/server.rb', line 47

def store(realm, identifier, scope)
  uuid = SecureRandom.uuid
  entry = find(realm, identifier)
  if entry.nil?
    Database::Resource.create(:identifier => identifier, :realm => realm, :scope => scope, :uuid => uuid)
  else
    entry.update({:scope => scope, :uuid => uuid})
    entry.save
  end
  uuid
end

Instance Method Details

#createObject

Raises:


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jerakia/scope/server.rb', line 29

def create
  realm = request.scope_options['realm']
  identifier = request.scope_options['identifier']

  raise Jerakia::Error, "Must supply realm and identifier for server scope handler" unless realm and identifier
  resource = Jerakia::Scope::Server.find(realm, identifier)
  raise Jerakia::Error, "No scope data found for realm:#{realm} identifier:#{identifier}" if resource.nil?
  scope = resource.scope
  raise Jerakia::Error, "Scope did not return a hash for realm:#{realm} identifier:#{identifier}" unless scope.is_a?(Hash)
  @value = Hash[ scope.map { |k,v| [ k.to_sym, v ] } ]
end