Class: ActiveDocument::DatabaseConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/ActiveDocument/database_configuration.rb

Overview

This class is used to manage the configuration of MarkLogic. It can create, list and change / delete a variety of configuration options including indexes namespaces and fields

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#namespacesObject (readonly)

Returns the value of attribute namespaces.



24
25
26
# File 'lib/ActiveDocument/database_configuration.rb', line 24

def namespaces
  @namespaces
end

Class Method Details

.define_namespaces(namespaces) ⇒ Object

Parameters:



35
36
37
38
39
40
# File 'lib/ActiveDocument/database_configuration.rb', line 35

def self.define_namespaces(namespaces)
  namespaces.keys.each do |key|
    corona_array = ActiveDocument::CoronaInterface.declare_namespace(key, namespaces[key])
    @@ml_http.send_corona_request(corona_array[0], corona_array[1])
  end
end

.delete_all_namespacesObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ActiveDocument/database_configuration.rb', line 57

def self.delete_all_namespaces
  corona_array = ActiveDocument::CoronaInterface.delete_all_namespaces
  begin
    @@ml_http.send_corona_request(corona_array[0], corona_array[1])
  rescue Exception => exception
    if exception.response && exception.response.code == "404"
      nil
    else
      raise exception
    end
  end
end

.initialize(yaml_file) ⇒ Object

Parameters:

  • yaml_file (The yaml file containing the configuration information for the server connection)


27
28
29
30
31
# File 'lib/ActiveDocument/database_configuration.rb', line 27

def self.initialize(yaml_file)
  config = YAML.load_file(yaml_file)
  @@ml_http = ActiveDocument::MarkLogicHTTP.new(config['uri'], config['user_name'], config['password'])
  @@namespaces = Hash.new
end

.lookup_namespace(prefix) ⇒ Object

Returns The matching namespace as a string or nil if there is no matching namespace for the prefix.

Parameters:

  • prefix (The prefix for which you wish to find a matching namespace)

Returns:

  • The matching namespace as a string or nil if there is no matching namespace for the prefix



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ActiveDocument/database_configuration.rb', line 44

def self.lookup_namespace(prefix)
  corona_array = ActiveDocument::CoronaInterface.lookup_namespace(prefix)
  begin
    @@ml_http.send_corona_request(corona_array[0], corona_array[1])
  rescue Exception => exception
    if exception.response.code == "404"
      nil #return nil when no namespace is found
    else
      raise exception
    end
  end
end