Class: AllegroGraph::Catalog

Inherits:
Object
  • Object
show all
Defined in:
lib/allegro_graph/catalog.rb

Overview

The Catalog class wrap the corresponding resource on the AllegroGraph server. A catalog can hold many repositories.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, name, options = { }) ⇒ Catalog

Returns a new instance of Catalog.



11
12
13
14
15
# File 'lib/allegro_graph/catalog.rb', line 11

def initialize(server, name, options = { })
  @server = server
  @name = name
  @root = options[:root] || false
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/allegro_graph/catalog.rb', line 9

def name
  @name
end

#serverObject (readonly)

Returns the value of attribute server.



8
9
10
# File 'lib/allegro_graph/catalog.rb', line 8

def server
  @server
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/allegro_graph/catalog.rb', line 17

def ==(other)
  other.is_a?(self.class) && self.server == other.server && self.root? == other.root? && self.name == other.name
end

#create!Object



33
34
35
36
37
38
39
# File 'lib/allegro_graph/catalog.rb', line 33

def create!
  @server.request_http :put, self.path, :expected_status_code => 204
  true
rescue ::Transport::UnexpectedStatusCodeError => error
  return false if error.status_code == 400
  raise error
end

#create_if_missing!Object



41
42
43
# File 'lib/allegro_graph/catalog.rb', line 41

def create_if_missing!
  create! unless exists?
end

#delete!Object



45
46
47
48
49
50
51
# File 'lib/allegro_graph/catalog.rb', line 45

def delete!
  @server.request_http :delete, self.path, :expected_status_code => 204
  true
rescue ::Transport::UnexpectedStatusCodeError => error
  return false if error.status_code == 400
  raise error
end

#delete_if_exists!Object



53
54
55
# File 'lib/allegro_graph/catalog.rb', line 53

def delete_if_exists!
  delete! if exists?
end

#exists?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/allegro_graph/catalog.rb', line 29

def exists?
  @server.catalogs.include? self
end

#pathObject



21
22
23
# File 'lib/allegro_graph/catalog.rb', line 21

def path
  self.root? ? "" : "/catalogs/#{@name}"
end

#repositoriesObject



57
58
59
60
# File 'lib/allegro_graph/catalog.rb', line 57

def repositories
  repositories = @server.request_json :get, self.path + "/repositories", :expected_status_code => 200
  repositories.map { |repository| Repository.new self, repository["id"] }
end

#root?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/allegro_graph/catalog.rb', line 25

def root?
  !!@root
end