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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: febbb8bf27d885ae1f8afc4f47fb1e18f8885785
4
- data.tar.gz: 7486e983ba4a28b7162a211a43cf0da75b16bf54
3
+ metadata.gz: 18864110b5fce7d741a7c69be950a5208445100c
4
+ data.tar.gz: 0e5a3a91f9d06fb81a6f81f1636a378d7a5042f2
5
5
  SHA512:
6
- metadata.gz: 033554916f5af9e158a6a620025c65d10a0e13bd9844f46b6455ee354133de2db68f40cce00f2d3c18ec6fb7c48f4b9ed3ad667cb55bde0b204fdb5ed50f7cdc
7
- data.tar.gz: 94fd757f3bafac485e0ff8b8b7b884be002685783ac6d599921e1a39efffb1703845a01853a469486c4e9c74ec73cf68b4926d11cb83a83db8c5fee168e2dc94
6
+ metadata.gz: 02062fe7716c174576880e11e27e97088ea0d8f3a4ec0043e28f5dc188180aa74f87e9020939dca8165ffd131858614dcb94fd809b3b6223361201f6d0463007
7
+ data.tar.gz: e4a20c6e03e918c0acdc810ab858655c863aea3f84e028818dc1e4bba9d4eac06ff6e325092f16f2b0abe90627e89ebc25e0fbf2513acecb100fbda721aed085
data/.gitignore CHANGED
@@ -1,5 +1,2 @@
1
1
  pkg
2
- Gemfile.lock
3
- mutx/
4
- mutx/*
5
2
  .DS_Store
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mutx (0.1.62)
4
+ mutx (0.1.63)
5
5
  basica
6
6
  bson_ext
7
7
  byebug
@@ -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
- #require 'mongoid'
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
- set_client(opts)
13
- set_db
14
- authenticate(opts)
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
@@ -1,3 +1,3 @@
1
1
  module Mutx
2
- VERSION = "0.1.62"
2
+ VERSION = "0.1.63"
3
3
  end
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.62
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-23 00:00:00.000000000 Z
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