Class: MarkLogic::Application

Inherits:
Object
  • Object
show all
Includes:
Persistence
Defined in:
lib/marklogic/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Persistence

#admin_connection, #admin_connection=, #connection, #connection=, #manage_connection, #manage_connection=

Methods included from Loggable

#default_logger, #logger, #logger=, #rails_logger

Constructor Details

#initialize(app_name, options = {}) ⇒ Application

Returns a new instance of Application.


7
8
9
10
11
12
# File 'lib/marklogic/application.rb', line 7

def initialize(app_name, options = {})
  @app_name = app_name
  self.connection = options[:connection]
  @port = options[:port] || self.connection.port
  self.admin_connection = options[:admin_connection]
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name


5
6
7
# File 'lib/marklogic/application.rb', line 5

def app_name
  @app_name
end

#portObject

Returns the value of attribute port


5
6
7
# File 'lib/marklogic/application.rb', line 5

def port
  @port
end

Class Method Details

.load(app_name, options = {}) ⇒ Object


197
198
199
200
201
# File 'lib/marklogic/application.rb', line 197

def self.load(app_name, options = {})
  app = Application.new(app_name, options)
  app.load
  app
end

Instance Method Details

#add_index(index) ⇒ Object


147
148
149
# File 'lib/marklogic/application.rb', line 147

def add_index(index)
  indexes[index.key] = index
end

#app_server(name) {|app_server| ... } ⇒ Object

Yields:


177
178
179
180
181
# File 'lib/marklogic/application.rb', line 177

def app_server(name)
  app_server = MarkLogic::AppServer.new(name, @port)
  app_servers[name] = app_server
  yield(app_server) if block_given?
end

#app_serversObject


143
144
145
# File 'lib/marklogic/application.rb', line 143

def app_servers
  @app_servers ||= {}
end

#clear_indexesObject


151
152
153
154
155
156
# File 'lib/marklogic/application.rb', line 151

def clear_indexes()
  content_databases.each do |database|
    database.reset_indexes
  end
  @indexes = {}
end

#config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:


183
184
185
186
# File 'lib/marklogic/application.rb', line 183

def config
  yield(self) if block_given?
  build_implicit_defs
end

#content_databasesObject


158
159
160
161
162
# File 'lib/marklogic/application.rb', line 158

def content_databases
  app_servers.values.map do |app_server|
    databases[app_server['content-database']]
  end
end

#createObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/marklogic/application.rb', line 14

def create
  logger.debug(%Q{Creating Application: #{@app_name}})

  build_implicit_defs

  databases.each do |database_name, database|
    unless database.exists?
      database.create
    else
      database.update
    end
  end

  forests.each do |forest_name, forest|
    forest.create unless forest.exists?
  end

  app_servers.each do |server_name, app_server|
    unless app_server.exists?
      app_server.create
    else
      app_server.update
    end
  end

end

#create_indexesObject


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/marklogic/application.rb', line 41

def create_indexes
  build_implicit_defs

  content_databases.each do |database|
    if database.exists?
      database.update
    else
      database.create
    end
  end
end

#database(name) {|database| ... } ⇒ Object

Yields:


170
171
172
173
174
175
# File 'lib/marklogic/application.rb', line 170

def database(name)
  database = MarkLogic::Database.new(name, self.connection)
  database.application = self
  databases[name] = database
  yield(database) if block_given?
end

#databasesObject


139
140
141
# File 'lib/marklogic/application.rb', line 139

def databases
  @databases ||= {}
end

#dropObject


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/marklogic/application.rb', line 61

def drop
  logger.debug(%Q{Dropping Application: #{@app_name}})

  build_implicit_defs

  app_servers.each do |server_name, app_server|
    app_server.drop if app_server.exists?
  end

  databases.each do |database_name, database|
    if database.exists?
      database.drop
    end
  end

  forests.each do |forest_name, forest|
    if forest.exists?
      forest.drop
    end
  end
end

#exists?Boolean

Returns:

  • (Boolean)

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/marklogic/application.rb', line 83

def exists?
  build_implicit_defs

  databases.each do |database_name, database|
    return false if !database.exists?
  end

  forests.each do |forest_name, forest|
    return false if !forest.exists?
  end

  app_servers.each do |server_name, app_server|
    return false if !app_server.exists?
  end

  return true
end

#forestsObject


135
136
137
# File 'lib/marklogic/application.rb', line 135

def forests
  @forests ||= {}
end

#inspectObject


188
189
190
191
192
193
194
195
# File 'lib/marklogic/application.rb', line 188

def inspect
  as_nice_string = [
    " app_name: #{app_name.inspect}",
    " port: #{port.inspect}",
    " app_servers: #{app_servers.values.each { |app_server| app_server.inspect }}"
  ].join(",")
  "#<#{self.class}#{as_nice_string}>"
end

#loadObject


203
204
205
206
207
208
# File 'lib/marklogic/application.rb', line 203

def load
  app_servers[app_name] = MarkLogic::AppServer.load(app_name)
  @port = app_servers[app_name]['port']
  load_databases
  build_indexes
end

#modules_databasesObject


164
165
166
167
168
# File 'lib/marklogic/application.rb', line 164

def modules_databases
  app_servers.values.map do |app_server|
    databases[app_server['modules-database']]
  end
end

#stale?Boolean

Returns:

  • (Boolean)

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/marklogic/application.rb', line 101

def stale?
  build_implicit_defs

  databases.each do |database_name, database|
    unless database.exists?
      logger.debug "database: #{database_name} is missing"
      return true
    end
  end

  content_databases.each do |database|
    if database.stale?
      logger.debug "database: #{database.database_name} is stale"
      return true
    end
  end

  forests.each do |forest_name, forest|
    unless forest.exists?
      logger.debug "forest: #{forest_name} is missing"
      return true
    end
  end

  app_servers.each do |server_name, app_server|
    unless app_server.exists?
      logger.debug "app_server: #{server_name} is missing"
      return true
    end
  end

  return false
end

#syncObject


53
54
55
# File 'lib/marklogic/application.rb', line 53

def sync
  create if stale?
end

#sync!Object


57
58
59
# File 'lib/marklogic/application.rb', line 57

def sync!
  create
end