mutx 0.1.62 → 0.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -3
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/lib/mutx/database/middleware.rb +18 -0
- data/lib/mutx/database/mongo_connection.rb +47 -0
- data/lib/mutx/database/mongo_connector.rb +14 -5
- data/lib/mutx/routes.rb +2 -2
- data/lib/mutx/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18864110b5fce7d741a7c69be950a5208445100c
|
4
|
+
data.tar.gz: 0e5a3a91f9d06fb81a6f81f1636a378d7a5042f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02062fe7716c174576880e11e27e97088ea0d8f3a4ec0043e28f5dc188180aa74f87e9020939dca8165ffd131858614dcb94fd809b3b6223361201f6d0463007
|
7
|
+
data.tar.gz: e4a20c6e03e918c0acdc810ab858655c863aea3f84e028818dc1e4bba9d4eac06ff6e325092f16f2b0abe90627e89ebc25e0fbf2513acecb100fbda721aed085
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mutx
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.0
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Mutx
|
2
|
+
module Database
|
3
|
+
class Middleware
|
4
|
+
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
configuration = Mutx::Support::Configuration.db_connection_data
|
11
|
+
Mutx::Database::MongoConnector.new(configuration)
|
12
|
+
@app.call(env)
|
13
|
+
ensure
|
14
|
+
Mutx::Database::MongoConnector.close
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'mongo'
|
3
|
+
|
4
|
+
module Mutx
|
5
|
+
module Database
|
6
|
+
class MongoConnection
|
7
|
+
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def client(**args)
|
11
|
+
mutex.synchronize {
|
12
|
+
@client ||= connect_to_database(args)
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def db
|
17
|
+
client.database
|
18
|
+
end
|
19
|
+
|
20
|
+
def close
|
21
|
+
mutex.synchronize {
|
22
|
+
@client.close if @client
|
23
|
+
@client = nil
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def mutex
|
30
|
+
@mutex ||= Mutex.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def connect_to_database(**args)
|
34
|
+
Mongo::Client.new(hosts(args), database: args[:database])
|
35
|
+
#authenticate(args[:username], args[:pass])
|
36
|
+
end
|
37
|
+
|
38
|
+
def hosts(**args)
|
39
|
+
["#{args[:host]}:#{args[:port]}"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def authenticate(username, password)
|
43
|
+
self.db.authenticate(username, password)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'mongo'
|
2
|
+
require_relative './mongo_connection'
|
4
3
|
|
5
4
|
module Mutx
|
6
5
|
module Database
|
@@ -9,9 +8,15 @@ module Mutx
|
|
9
8
|
#include Mongo
|
10
9
|
|
11
10
|
def initialize(opts={host: "localhost", port: 27017, username: nil, pass: nil})
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
project_name = Dir.pwd.split("/").last
|
12
|
+
mongo_connection = MongoConnection.instance
|
13
|
+
mongo_connection.client(host: opts[:host],
|
14
|
+
port: opts[:port],
|
15
|
+
database: "#{project_name}_mutx",
|
16
|
+
username: opts[:username],
|
17
|
+
password: opts[:pass])
|
18
|
+
|
19
|
+
$db = mongo_connection.db
|
15
20
|
set_task_collection
|
16
21
|
set_custom_param_collection
|
17
22
|
set_config_collection
|
@@ -48,6 +53,10 @@ module Mutx
|
|
48
53
|
$client = $client.close if $client
|
49
54
|
end
|
50
55
|
|
56
|
+
def self.close
|
57
|
+
MongoConnection.instance.close
|
58
|
+
end
|
59
|
+
|
51
60
|
def set_db
|
52
61
|
Mutx::Support::Log.debug "Setting db" if Mutx::Support::Log
|
53
62
|
$db = $client.database
|
data/lib/mutx/routes.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "cuba"
|
3
3
|
#include Basica
|
4
|
+
require_relative './database/middleware'
|
4
5
|
|
6
|
+
Cuba.use Mutx::Database::Middleware
|
5
7
|
Cuba.plugin Basica
|
6
8
|
|
7
9
|
include Mote::Helpers
|
@@ -11,8 +13,6 @@ Mutx::Support::Configuration.get
|
|
11
13
|
|
12
14
|
Cuba.define do
|
13
15
|
|
14
|
-
Mutx::Database::MongoConnector.new Mutx::Support::Configuration.db_connection_data
|
15
|
-
|
16
16
|
$tasks_counter = 0
|
17
17
|
|
18
18
|
request = Mutx::Support::Request.new(req)
|
data/lib/mutx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.63
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Rodriguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -356,6 +356,8 @@ extensions: []
|
|
356
356
|
extra_rdoc_files: []
|
357
357
|
files:
|
358
358
|
- ".gitignore"
|
359
|
+
- ".ruby-gemset"
|
360
|
+
- ".ruby-version"
|
359
361
|
- Gemfile
|
360
362
|
- Gemfile.lock
|
361
363
|
- LICENSE.txt
|
@@ -429,6 +431,8 @@ files:
|
|
429
431
|
- lib/mutx/custom/execution.rb
|
430
432
|
- lib/mutx/custom/params.rb
|
431
433
|
- lib/mutx/database/.DS_Store
|
434
|
+
- lib/mutx/database/middleware.rb
|
435
|
+
- lib/mutx/database/mongo_connection.rb
|
432
436
|
- lib/mutx/database/mongo_connector.rb
|
433
437
|
- lib/mutx/error/errors.rb
|
434
438
|
- lib/mutx/execution.rb
|