Sha256: df0fdc38d3878b9750f38afd0ad5d201801b71de267844b02d0ce04cad672255

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

module MarkLogic
  class Forest
    include MarkLogic::Persistence

    attr_accessor :forest_name
    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

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

    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

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

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

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

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

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

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
marklogic-0.0.11 lib/marklogic/forest.rb
marklogic-0.0.10 lib/marklogic/forest.rb
marklogic-0.0.9 lib/marklogic/forest.rb
marklogic-0.0.8 lib/marklogic/forest.rb
marklogic-0.0.7 lib/marklogic/forest.rb
marklogic-0.0.6 lib/marklogic/forest.rb
marklogic-0.0.5 lib/marklogic/forest.rb
marklogic-0.0.4 lib/marklogic/forest.rb
marklogic-0.0.3 lib/marklogic/forest.rb