Class: MarkLogic::Forest

Inherits:
Object
  • Object
show all
Includes:
Persistence
Defined in:
lib/marklogic/forest.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(forest_name, host_name = nil, conn = nil) ⇒ Forest

Returns a new instance of Forest.


6
7
8
9
10
11
12
13
14
# File 'lib/marklogic/forest.rb', line 6

def initialize(forest_name, host_name = nil, conn = nil)
  self.connection = conn
  @forest_name = forest_name
  @host_name = host_name || self.manage_connection.host
  @options = {
    "forest-name" => @forest_name,
    "host" => @host_name
  }
end

Instance Attribute Details

#forest_nameObject

Returns the value of attribute forest_name


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

def forest_name
  @forest_name
end

Class Method Details

.load(forest_name, host_name = nil, conn = nil) ⇒ Object


16
17
18
19
20
# File 'lib/marklogic/forest.rb', line 16

def self.load(forest_name, host_name = nil, conn = nil)
  db = Forest.new(forest_name, host_name, conn)
  db.load
  db
end

Instance Method Details

#[](key) ⇒ Object


36
37
38
# File 'lib/marklogic/forest.rb', line 36

def [](key)
  @options[key]
end

#[]=(key, value) ⇒ Object


32
33
34
# File 'lib/marklogic/forest.rb', line 32

def []=(key, value)
  @options[key] = value
end

#createObject


49
50
51
52
53
# File 'lib/marklogic/forest.rb', line 49

def create
  r = manage_connection.post_json(
    %Q{/manage/v2/forests?format=json},
    @options)
end

#database=(db) ⇒ Object


44
45
46
47
# File 'lib/marklogic/forest.rb', line 44

def database=(db)
  @database = db
  @options['database'] = db.database_name
end

#dropObject


59
60
61
# File 'lib/marklogic/forest.rb', line 59

def drop
  r = manage_connection.delete(%Q{/manage/v2/forests/#{forest_name}?level=full&format=json})
end

#exists?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'lib/marklogic/forest.rb', line 55

def exists?
  manage_connection.head(%Q{/manage/v2/forests/#{forest_name}}).code.to_i == 200
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/marklogic/forest.rb', line 40

def has_key?(key)
  @options.has_key?(key)
end

#loadObject


22
23
24
25
26
27
28
29
30
# File 'lib/marklogic/forest.rb', line 22

def load
  resp = manage_connection.get(%Q{/manage/v2/forests/#{forest_name}/properties?format=json})
  if resp.code.to_i == 200
    options = Oj.load(resp.body)
    options.each do |key, value|
      self[key] = value
    end
  end
end