Class: Keymaker::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/keymaker/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
# File 'lib/keymaker/configuration.rb', line 9

def initialize(attrs={})
  self.protocol       = attrs.fetch(:protocol) {'http'}
  self.server         = attrs.fetch(:server) {'localhost'}
  self.port           = attrs.fetch(:port) {7474}
  self.authentication = attrs.fetch(:authentication) {{}}
  self.username       = attrs.fetch(:username) {nil}
  self.password       = attrs.fetch(:password) {nil}
  self.data_directory = 'db/data'
end

Instance Attribute Details

#authenticationObject

Returns the value of attribute authentication.



6
7
8
# File 'lib/keymaker/configuration.rb', line 6

def authentication
  @authentication
end

#data_directoryObject

Returns the value of attribute data_directory.



6
7
8
# File 'lib/keymaker/configuration.rb', line 6

def data_directory
  @data_directory
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/keymaker/configuration.rb', line 6

def password
  @password
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/keymaker/configuration.rb', line 6

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



6
7
8
# File 'lib/keymaker/configuration.rb', line 6

def protocol
  @protocol
end

#serverObject

Returns the value of attribute server.



6
7
8
# File 'lib/keymaker/configuration.rb', line 6

def server
  @server
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/keymaker/configuration.rb', line 6

def username
  @username
end

Instance Method Details

#batch_pathObject



68
69
70
# File 'lib/keymaker/configuration.rb', line 68

def batch_path
  service_root.batch
end

#connection_service_root_urlObject



35
36
37
# File 'lib/keymaker/configuration.rb', line 35

def connection_service_root_url
  Addressable::URI.new(connection_url_opts)
end

#connection_url_optsObject



39
40
41
42
43
44
# File 'lib/keymaker/configuration.rb', line 39

def connection_url_opts
  url_opts.tap do |url_opts|
    url_opts[:user] = username if username
    url_opts[:password] = password if password
  end
end

#full_cypher_pathObject

paths



48
49
50
# File 'lib/keymaker/configuration.rb', line 48

def full_cypher_path
  service_root.cypher
end

#full_gremlin_pathObject



52
53
54
# File 'lib/keymaker/configuration.rb', line 52

def full_gremlin_path
  service_root.extensions.fetch('GremlinPlugin', {}).fetch('execute_script', nil)
end

#node_full_index_path(index_name, key, value, node_id) ⇒ Object



84
85
86
# File 'lib/keymaker/configuration.rb', line 84

def node_full_index_path(index_name, key, value, node_id)
  [node_index_path(index_name), key, value, node_id].join("/")
end

#node_index_path(index_name) ⇒ Object



88
89
90
# File 'lib/keymaker/configuration.rb', line 88

def node_index_path(index_name)
  [service_root.node_index, index_name.to_s].join("/")
end

#node_pathObject



56
57
58
# File 'lib/keymaker/configuration.rb', line 56

def node_path
  service_root.node
end

#node_properties_path(node_id) ⇒ Object



60
61
62
# File 'lib/keymaker/configuration.rb', line 60

def node_properties_path(node_id)
  [node_path, node_id.to_s, 'properties'].join('/')
end

#node_uri(node_id) ⇒ Object



64
65
66
# File 'lib/keymaker/configuration.rb', line 64

def node_uri(node_id)
  [node_path, node_id.to_s].join("/")
end

#relationship_path(relationship_id) ⇒ Object



72
73
74
# File 'lib/keymaker/configuration.rb', line 72

def relationship_path(relationship_id)
  [data_directory, "relationship", relationship_id.to_s].join("/")
end

#relationship_types_pathObject



76
77
78
# File 'lib/keymaker/configuration.rb', line 76

def relationship_types_path
  service_root.relationship_types
end

#relationships_path_for_node(node_id) ⇒ Object



80
81
82
# File 'lib/keymaker/configuration.rb', line 80

def relationships_path_for_node(node_id)
  [node_path, node_id.to_s, "relationships"].join("/")
end

#service_rootObject



19
20
21
# File 'lib/keymaker/configuration.rb', line 19

def service_root
  @service_root ||= Keymaker.service.service_root_request.body
end

#service_root_urlObject



23
24
25
# File 'lib/keymaker/configuration.rb', line 23

def service_root_url
  Addressable::URI.new(url_opts)
end

#url_optsObject



27
28
29
30
31
32
33
# File 'lib/keymaker/configuration.rb', line 27

def url_opts
  {}.tap do |url_opts|
    url_opts[:scheme] = protocol
    url_opts[:host] = server
    url_opts[:port] = port
  end
end