angradb 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7439984b19be1cff9f9a121284739e25aa0551a4ccfd2698b1cb2e65bd20ca62
4
+ data.tar.gz: 4f718f430c02c012d399fbad7951498880f6c8148d1e610addff4fc950e2fdc3
5
+ SHA512:
6
+ metadata.gz: ef3f36eaf82df4567c3e0549d0da71589736bea64af7c4302df94f772553e02390640bd2e387153df2bbcf65166233d388b671a19638f53587e3763cc7e8656d
7
+ data.tar.gz: 5f1a8254150c8bc877be2afa5b5ccbdc15c9496a7299cb8ffb8b60145a73b07c52645b8419b09b6a570a249e161af30519a7ced9d4c23bf874d77c0982f00ba7
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in angradb.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jadiel Teófilo Amorim de Oliveira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "angradb/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "angradb"
8
+ spec.version = Angradb::VERSION
9
+ spec.authors = ["Jadiel Teófilo"]
10
+ spec.email = ["teofilojadiel@gmail.com"]
11
+
12
+ spec.summary = "A ruby gem to interface with Angradb"
13
+ spec.description = "A gem that makes a tcp connection with Angradb and allows operations related with it"
14
+ spec.homepage = "https://github.com/Angra-DB/angra-ruby-driver"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "byebug"
35
+ spec.add_development_dependency "json"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "angradb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,118 @@
1
+ require "angradb/version"
2
+ require "socket"
3
+ require 'json'
4
+
5
+ module Angradb
6
+ class Driver
7
+ BUFFER_SIZE = 1024
8
+ @ip_address = nil
9
+ @ip_port = nil
10
+ @session = nil
11
+
12
+ def initialize(ip_address, ip_port)
13
+ @ip_address = ip_address
14
+ @ip_port = ip_port
15
+ open_tcp_connection
16
+ end
17
+
18
+ # Connects to a specific database on Angradb
19
+ # Params:
20
+ # +db_name+:: name of the database
21
+ # Returns:
22
+ # +response+:: response of the server
23
+ def connect(db_name)
24
+ request = 'connect ' + db_name
25
+ response = send_to_server request
26
+ raise response if response.include? 'does not exist'
27
+ response
28
+ end
29
+
30
+ # Creates a specific database on Angradb
31
+ # Params:
32
+ # +db_name+:: name of the database
33
+ # Returns:
34
+ # +response+:: response of the server
35
+ def create_db(db_name)
36
+ request = 'create_db ' + db_name
37
+ send_to_server request
38
+ end
39
+
40
+ # Creates a document on the connected database of Angradb
41
+ # Params:
42
+ # +doc+:: document to be saved
43
+ # Returns:
44
+ # +key+:: returns the key for the saved document
45
+ def save(doc)
46
+ request = 'save ' + doc
47
+ begin
48
+ response = send_to_server request
49
+ rescue
50
+ raise 'Error on saving the document: ' + response.to_s
51
+ end
52
+
53
+ # returns the key without the quotes
54
+ response.delete '"'
55
+ end
56
+
57
+ # Updates a document on the connected database of Angradb
58
+ # Params:
59
+ # +key+:: the key for the document
60
+ # +doc+:: document to be saved
61
+ # # Returns:
62
+ # +response+:: response of the server
63
+ def update(key, doc)
64
+ request = 'update ' + key + ' ' + doc
65
+ response = send_to_server request
66
+ raise 'Error on updating the document: ' + response unless response == "ok"
67
+ # returns the key without the quotes
68
+ response
69
+ end
70
+
71
+ # Looks up a document on the connected database on Angradb
72
+ # Params:
73
+ # +key+:: the key for the document
74
+ # # Returns:
75
+ # +response+:: the requested document
76
+ def look_up(key)
77
+ request = 'lookup ' + key
78
+ response = send_to_server request
79
+ raise 'Error on lookup of the document: ' + response if response == "not_found"
80
+ # returns the key without the quotes
81
+ response
82
+ end
83
+
84
+ # Deletes a document on the connected database on Angradb
85
+ # Params:
86
+ # +key+:: the key for the document
87
+ # # Returns:
88
+ # +response+:: the server response
89
+ def delete(key)
90
+ raise 'A key should be provided' unless key
91
+ request = 'delete ' + key
92
+ response = send_to_server request
93
+ raise 'Error deleting the document: ' + response unless response == "ok"
94
+ # returns the key without the quotes
95
+ response
96
+ end
97
+
98
+ private
99
+
100
+ def open_tcp_connection
101
+ begin
102
+ @session = TCPSocket.new @ip_address, @ip_port
103
+ rescue
104
+ raise 'Couldnt connect with the socket-server'
105
+ end
106
+ end
107
+
108
+ def send_to_server(request)
109
+ @session.write(request)
110
+ treat_response @session.gets
111
+ end
112
+
113
+ def treat_response(string)
114
+ string.chomp # removes \n
115
+ # JSON.parse(string)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,3 @@
1
+ module Angradb
2
+ VERSION = "1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angradb
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Jadiel Teófilo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: A gem that makes a tcp connection with Angradb and allows operations
84
+ related with it
85
+ email:
86
+ - teofilojadiel@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - Rakefile
96
+ - angradb.gemspec
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/angradb.rb
100
+ - lib/angradb/version.rb
101
+ homepage: https://github.com/Angra-DB/angra-ruby-driver
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A ruby gem to interface with Angradb
126
+ test_files: []