functionator 0.1.0
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 +7 -0
- data/Gemfile +5 -0
- data/README.md +129 -0
- data/functionator.gemspec +22 -0
- data/lib/functionator/mongodb/client.rb +169 -0
- data/lib/functionator/version.rb +3 -0
- data/lib/functionator.rb +12 -0
- data/lib/mongodb_factory/client.rb +167 -0
- data/lib/mongodb_factory/version.rb +3 -0
- data/lib/mongodb_factory.rb +12 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a60f63f5b13bd75c67507ee3326b6db811411036f5df352f3987ab464891dbd8
|
4
|
+
data.tar.gz: 5f11f90e991f592ddb9c54d522d7ca57188ca75b71cd63b68dded9fc314e7a54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09d242b6e2c17e859bc843f61e0212bddcfa132fbb845a26c474c19b4049beb34fb60c8678d7ff8aa41ae444aca010c7f5e52250181f83fa26215d4f1585c00f'
|
7
|
+
data.tar.gz: 3a6983b3ae5705389621e2d60f24f1344fa0efc59f131017badbe1cd1c44f95ad2d3c6654f06e6364fcdc7dd041bd740273e45b24ba12826a53fe71413841fc0
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Functionator
|
2
|
+
|
3
|
+
Uma gem Ruby multi-funcional que fornece diversas funcionalidades organizadas em módulos, incluindo um cliente MongoDB com padrão Singleton e operações comuns de banco de dados.
|
4
|
+
|
5
|
+
## Instalação
|
6
|
+
|
7
|
+
Adicione esta linha ao seu Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'functionator'
|
11
|
+
```
|
12
|
+
|
13
|
+
E execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Ou instale diretamente:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install functionator
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuração
|
26
|
+
|
27
|
+
Configure as variáveis de ambiente para conexão com MongoDB:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
# Opção 1: Variáveis padrão
|
31
|
+
export USER=seu_usuario_mongodb
|
32
|
+
export PASSWORD=sua_senha_mongodb
|
33
|
+
export HOST=seu_host_mongodb
|
34
|
+
export DATABASE=seu_database_mongodb
|
35
|
+
|
36
|
+
# Opção 2: Variáveis específicas do MongoDB
|
37
|
+
export MONGODB_USER=seu_usuario_mongodb
|
38
|
+
export MONGODB_PASSWORD=sua_senha_mongodb
|
39
|
+
export MONGODB_HOST=seu_host_mongodb
|
40
|
+
export MONGODB_DATABASE=seu_database_mongodb
|
41
|
+
```
|
42
|
+
|
43
|
+
## Uso
|
44
|
+
|
45
|
+
### Básico
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'functionator'
|
49
|
+
|
50
|
+
# Usando o módulo MongoDB com padrão Singleton
|
51
|
+
client = Functionator.mongodb
|
52
|
+
|
53
|
+
# Ou acessando diretamente
|
54
|
+
client = Functionator::MongoDB::Client.instance
|
55
|
+
|
56
|
+
# Ou criando uma nova instância com string de conexão customizada
|
57
|
+
client = Functionator::MongoDB::Client.new("mongodb://localhost:27017/meu_database")
|
58
|
+
```
|
59
|
+
|
60
|
+
### Operações CRUD
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# Inserir múltiplos documentos
|
64
|
+
data = [
|
65
|
+
{ name: "João", age: 30 },
|
66
|
+
{ name: "Maria", age: 25 }
|
67
|
+
]
|
68
|
+
client.insert_many("users", data)
|
69
|
+
|
70
|
+
# Buscar documentos
|
71
|
+
users = client.find("users", { age: { "$gte" => 25 } })
|
72
|
+
|
73
|
+
# Buscar com ordenação e limite
|
74
|
+
recent_users = client.find_sort("users", {}, { created_at: -1 }, 10)
|
75
|
+
|
76
|
+
# Atualizar documento
|
77
|
+
client.update("users", { name: "João" }, { "$set" => { age: 31 } })
|
78
|
+
```
|
79
|
+
|
80
|
+
### Operações Especializadas
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# Contar status de requests (método específico do domínio)
|
84
|
+
status_counts = client.count_status_requests("requests")
|
85
|
+
|
86
|
+
# Upsert de logs
|
87
|
+
document = { ms: 1234567890, message: "Log entry", created_at: Time.now }
|
88
|
+
client.upsert_log_to_mongo("logs", document)
|
89
|
+
|
90
|
+
# Buscar grupos de log
|
91
|
+
log_groups = client.fetch_log_groups_from_mongo
|
92
|
+
|
93
|
+
# Obter última execução
|
94
|
+
last_run = client.get_last_run_from_mongo("executions", 1234567890)
|
95
|
+
```
|
96
|
+
|
97
|
+
## Métodos Disponíveis
|
98
|
+
|
99
|
+
- `insert_many(collection_name, data)` - Insere múltiplos documentos
|
100
|
+
- `find(collection_name, query)` - Busca documentos
|
101
|
+
- `find_sort(collection_name, query, sort, limit)` - Busca com ordenação e limite
|
102
|
+
- `update(collection_name, query, update_query)` - Atualiza documento
|
103
|
+
- `update_log_group(collection_name, query, update_query, upsert: false)` - Atualiza com opção de upsert
|
104
|
+
- `count_status_requests(collection_name)` - Conta status de requests por domínio
|
105
|
+
- `upsert_log_to_mongo(collection_name, document)` - Upsert de logs
|
106
|
+
- `upsert_log_to_mongo_log_group(collection_name, document)` - Upsert de grupos de log
|
107
|
+
- `fetch_log_groups_from_mongo` - Busca grupos de log
|
108
|
+
- `get_last_run_from_mongo(collection_name, ms)` - Obtém última execução
|
109
|
+
|
110
|
+
## Desenvolvimento
|
111
|
+
|
112
|
+
Após clonar o repositório:
|
113
|
+
|
114
|
+
```bash
|
115
|
+
$ bundle install
|
116
|
+
$ rake spec # Para executar os testes
|
117
|
+
```
|
118
|
+
|
119
|
+
## Contribuição
|
120
|
+
|
121
|
+
1. Faça um Fork do projeto
|
122
|
+
2. Crie uma branch para sua feature (`git checkout -b my-new-feature`)
|
123
|
+
3. Commit suas mudanças (`git commit -am 'Add some feature'`)
|
124
|
+
4. Push para a branch (`git push origin my-new-feature`)
|
125
|
+
5. Crie um Pull Request
|
126
|
+
|
127
|
+
## Licença
|
128
|
+
|
129
|
+
Esta gem está disponível como código aberto sob os termos da [Licença MIT](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'lib/functionator/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "functionator"
|
5
|
+
spec.version = Functionator::VERSION
|
6
|
+
spec.authors = ["Kaique Leonardo"]
|
7
|
+
spec.email = ["kaique.silva@terceiros-sky.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{A MongoDB client factory with common operations}
|
10
|
+
spec.description = %q{Functionator - A Ruby gem that provides a MongoDB client factory with singleton pattern and common database operations like insert, find, update, and aggregation queries.}
|
11
|
+
spec.homepage = "https://github.com/seuusuario/functionator"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = Dir["lib/**/*", "README.md", "Gemfile", "functionator.gemspec"]
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_dependency "mongo", "~> 2.18"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
20
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
21
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
22
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
|
3
|
+
module Functionator
|
4
|
+
module MongoDB
|
5
|
+
class Client
|
6
|
+
@instance = nil
|
7
|
+
|
8
|
+
def self.instance
|
9
|
+
@instance ||= new
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(connection_string = nil)
|
13
|
+
@connection_string = connection_string || build_connection_string
|
14
|
+
@client = Mongo::Client.new(@connection_string)
|
15
|
+
end
|
16
|
+
|
17
|
+
def client
|
18
|
+
@client
|
19
|
+
end
|
20
|
+
|
21
|
+
def insert_many(collection_name, data)
|
22
|
+
client[collection_name.to_sym].insert_many(data)
|
23
|
+
rescue StandardError => e
|
24
|
+
puts "Error: #{e.message}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(collection_name, query)
|
28
|
+
client[collection_name.to_sym].find(query).to_a
|
29
|
+
rescue StandardError => e
|
30
|
+
puts "Error: #{e.message}"
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_sort(collection_name, query, sort, limit)
|
35
|
+
client[collection_name.to_sym].find(query).sort(sort).limit(limit).to_a
|
36
|
+
rescue StandardError => e
|
37
|
+
puts "Error: #{e.message}"
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
|
41
|
+
def update(collection_name, query, query_up)
|
42
|
+
client[collection_name.to_sym].update_one(query, query_up)
|
43
|
+
rescue StandardError => e
|
44
|
+
puts "Error: #{e.message}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_log_group(collection_name, query, query_up, upsert: false)
|
48
|
+
client[collection_name.to_sym].update_one(query, query_up, upsert: upsert)
|
49
|
+
rescue StandardError => e
|
50
|
+
puts "Error: #{e.message}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def count_status_requests(collection_name)
|
54
|
+
begin
|
55
|
+
pipeline = [
|
56
|
+
{ '$match' => { 'status' => { '$regex' => '^(Success|Failure)', '$options' => 'i' } } },
|
57
|
+
{ '$project' => {
|
58
|
+
'domain' => 1,
|
59
|
+
'status_code' => {
|
60
|
+
'$let' => {
|
61
|
+
'vars' => {
|
62
|
+
'regex_result' => {
|
63
|
+
'$regexFind' => {
|
64
|
+
'input' => '$status',
|
65
|
+
'regex' => 'HTTP Status Code (\d{3})',
|
66
|
+
'options' => 'i'
|
67
|
+
}
|
68
|
+
}
|
69
|
+
},
|
70
|
+
'in' => { '$ifNull' => ['$$regex_result.match', 'N/A'] }
|
71
|
+
}
|
72
|
+
},
|
73
|
+
'status' => 1
|
74
|
+
}
|
75
|
+
},
|
76
|
+
{ '$group' => {
|
77
|
+
'_id' => '$domain',
|
78
|
+
'total' => { '$sum' => 1 },
|
79
|
+
'status_success' => { '$sum' => { '$cond' => [{ '$regexMatch' => { 'input' => '$status', 'regex' => '^Success', 'options' => 'i' } }, 1, 0] } },
|
80
|
+
'status_failure' => { '$sum' => { '$cond' => [{ '$regexMatch' => { 'input' => '$status', 'regex' => '^Failure', 'options' => 'i' } }, 1, 0] } },
|
81
|
+
'status_codes' => { '$push' => '$status_code' }
|
82
|
+
}
|
83
|
+
},
|
84
|
+
{ '$project' => {
|
85
|
+
'domain' => '$_id',
|
86
|
+
'total_requests' => '$total',
|
87
|
+
'status_success' => 1,
|
88
|
+
'status_failure' => 1,
|
89
|
+
'status_codes' => 1,
|
90
|
+
'_id' => 0
|
91
|
+
}
|
92
|
+
}
|
93
|
+
]
|
94
|
+
|
95
|
+
result = client[collection_name.to_sym].aggregate(pipeline).to_a
|
96
|
+
result.map do |client_data|
|
97
|
+
status_codes_count = client_data['status_codes'].tally
|
98
|
+
{
|
99
|
+
domain: client_data['domain'],
|
100
|
+
total_requests: client_data['total_requests'] || 0,
|
101
|
+
status_success: client_data['status_success'] || 0,
|
102
|
+
status_failure: client_data['status_failure'] || 0,
|
103
|
+
status_codes_count: status_codes_count
|
104
|
+
}
|
105
|
+
end
|
106
|
+
rescue StandardError => e
|
107
|
+
puts "Error: #{e.message}"
|
108
|
+
[]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def upsert_log_to_mongo(collection_name, document)
|
113
|
+
existing_document = find(collection_name, { ms: document[:ms] }).first
|
114
|
+
document.delete(:created_at) if existing_document
|
115
|
+
result = update(collection_name, { ms: document[:ms] }, { '$set' => document })
|
116
|
+
|
117
|
+
if result&.upserted_count&.positive?
|
118
|
+
puts "Inserted new document for ms: #{document[:ms]}"
|
119
|
+
else
|
120
|
+
puts "Updated document for ms: #{document[:ms]}"
|
121
|
+
end
|
122
|
+
rescue StandardError => e
|
123
|
+
puts "Error upserting into MongoDB: #{e.message}"
|
124
|
+
end
|
125
|
+
|
126
|
+
def upsert_log_to_mongo_log_group(collection_name, document)
|
127
|
+
existing_document = find(collection_name, { ms: document[:ms] }).first
|
128
|
+
document.delete(:created_at) if existing_document
|
129
|
+
result = update_log_group(collection_name, { ms: document[:ms] }, { '$set' => document }, upsert: true)
|
130
|
+
|
131
|
+
if result&.upserted_count&.positive?
|
132
|
+
puts "Inserted new document for ms: #{document[:ms]}"
|
133
|
+
else
|
134
|
+
puts "Updated document for ms: #{document[:ms]}"
|
135
|
+
end
|
136
|
+
rescue StandardError => e
|
137
|
+
puts "Error upserting into MongoDB: #{e.message}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def fetch_log_groups_from_mongo
|
141
|
+
log_groups = {}
|
142
|
+
find('log_group_lambda', {}).each do |doc|
|
143
|
+
next unless doc['ms'] && doc['log_groups'].is_a?(Array)
|
144
|
+
log_groups[doc['ms']] = doc['log_groups']
|
145
|
+
end
|
146
|
+
log_groups
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_last_run_from_mongo(collection_name, ms)
|
150
|
+
collection = find_sort(collection_name, { ms: ms }, { last_run: -1 }, 1).first
|
151
|
+
collection ? collection[:last_run] : nil
|
152
|
+
rescue StandardError => e
|
153
|
+
puts "Error fetching last_run: #{e.message}"
|
154
|
+
nil
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def build_connection_string
|
160
|
+
user = ENV['USER'] || ENV['MONGODB_USER']
|
161
|
+
password = ENV['PASSWORD'] || ENV['MONGODB_PASSWORD']
|
162
|
+
host = ENV['HOST'] || ENV['MONGODB_HOST']
|
163
|
+
database = ENV['DATABASE'] || ENV['MONGODB_DATABASE']
|
164
|
+
|
165
|
+
"mongodb+srv://#{user}:#{password}@#{host}/#{database}?retryWrites=true&w=majority&readPreference=primaryPreferred"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
data/lib/functionator.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative 'functionator/version'
|
2
|
+
require_relative 'functionator/mongodb/client'
|
3
|
+
|
4
|
+
module Functionator
|
5
|
+
# Entry point for the Functionator gem
|
6
|
+
# A multi-purpose library with various functionalities
|
7
|
+
|
8
|
+
# MongoDB functionality
|
9
|
+
def self.mongodb
|
10
|
+
Functionator::MongoDB::Client.instance
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
|
3
|
+
module MongodbFactory
|
4
|
+
class Client
|
5
|
+
@instance = nil
|
6
|
+
|
7
|
+
def self.instance
|
8
|
+
@instance ||= new
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(connection_string = nil)
|
12
|
+
@connection_string = connection_string || build_connection_string
|
13
|
+
@client = Mongo::Client.new(@connection_string)
|
14
|
+
end
|
15
|
+
|
16
|
+
def client
|
17
|
+
@client
|
18
|
+
end
|
19
|
+
|
20
|
+
def insert_many(collection_name, data)
|
21
|
+
client[collection_name.to_sym].insert_many(data)
|
22
|
+
rescue StandardError => e
|
23
|
+
puts "Error: #{e.message}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def find(collection_name, query)
|
27
|
+
client[collection_name.to_sym].find(query).to_a
|
28
|
+
rescue StandardError => e
|
29
|
+
puts "Error: #{e.message}"
|
30
|
+
[]
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_sort(collection_name, query, sort, limit)
|
34
|
+
client[collection_name.to_sym].find(query).sort(sort).limit(limit).to_a
|
35
|
+
rescue StandardError => e
|
36
|
+
puts "Error: #{e.message}"
|
37
|
+
[]
|
38
|
+
end
|
39
|
+
|
40
|
+
def update(collection_name, query, query_up)
|
41
|
+
client[collection_name.to_sym].update_one(query, query_up)
|
42
|
+
rescue StandardError => e
|
43
|
+
puts "Error: #{e.message}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_log_group(collection_name, query, query_up, upsert: false)
|
47
|
+
client[collection_name.to_sym].update_one(query, query_up, upsert: upsert)
|
48
|
+
rescue StandardError => e
|
49
|
+
puts "Error: #{e.message}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def count_status_requests(collection_name)
|
53
|
+
begin
|
54
|
+
pipeline = [
|
55
|
+
{ '$match' => { 'status' => { '$regex' => '^(Success|Failure)', '$options' => 'i' } } },
|
56
|
+
{ '$project' => {
|
57
|
+
'domain' => 1,
|
58
|
+
'status_code' => {
|
59
|
+
'$let' => {
|
60
|
+
'vars' => {
|
61
|
+
'regex_result' => {
|
62
|
+
'$regexFind' => {
|
63
|
+
'input' => '$status',
|
64
|
+
'regex' => 'HTTP Status Code (\d{3})',
|
65
|
+
'options' => 'i'
|
66
|
+
}
|
67
|
+
}
|
68
|
+
},
|
69
|
+
'in' => { '$ifNull' => ['$$regex_result.match', 'N/A'] }
|
70
|
+
}
|
71
|
+
},
|
72
|
+
'status' => 1
|
73
|
+
}
|
74
|
+
},
|
75
|
+
{ '$group' => {
|
76
|
+
'_id' => '$domain',
|
77
|
+
'total' => { '$sum' => 1 },
|
78
|
+
'status_success' => { '$sum' => { '$cond' => [{ '$regexMatch' => { 'input' => '$status', 'regex' => '^Success', 'options' => 'i' } }, 1, 0] } },
|
79
|
+
'status_failure' => { '$sum' => { '$cond' => [{ '$regexMatch' => { 'input' => '$status', 'regex' => '^Failure', 'options' => 'i' } }, 1, 0] } },
|
80
|
+
'status_codes' => { '$push' => '$status_code' }
|
81
|
+
}
|
82
|
+
},
|
83
|
+
{ '$project' => {
|
84
|
+
'domain' => '$_id',
|
85
|
+
'total_requests' => '$total',
|
86
|
+
'status_success' => 1,
|
87
|
+
'status_failure' => 1,
|
88
|
+
'status_codes' => 1,
|
89
|
+
'_id' => 0
|
90
|
+
}
|
91
|
+
}
|
92
|
+
]
|
93
|
+
|
94
|
+
result = client[collection_name.to_sym].aggregate(pipeline).to_a
|
95
|
+
result.map do |client_data|
|
96
|
+
status_codes_count = client_data['status_codes'].tally
|
97
|
+
{
|
98
|
+
domain: client_data['domain'],
|
99
|
+
total_requests: client_data['total_requests'] || 0,
|
100
|
+
status_success: client_data['status_success'] || 0,
|
101
|
+
status_failure: client_data['status_failure'] || 0,
|
102
|
+
status_codes_count: status_codes_count
|
103
|
+
}
|
104
|
+
end
|
105
|
+
rescue StandardError => e
|
106
|
+
puts "Error: #{e.message}"
|
107
|
+
[]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def upsert_log_to_mongo(collection_name, document)
|
112
|
+
existing_document = find(collection_name, { ms: document[:ms] }).first
|
113
|
+
document.delete(:created_at) if existing_document
|
114
|
+
result = update(collection_name, { ms: document[:ms] }, { '$set' => document })
|
115
|
+
|
116
|
+
if result&.upserted_count&.positive?
|
117
|
+
puts "Inserted new document for ms: #{document[:ms]}"
|
118
|
+
else
|
119
|
+
puts "Updated document for ms: #{document[:ms]}"
|
120
|
+
end
|
121
|
+
rescue StandardError => e
|
122
|
+
puts "Error upserting into MongoDB: #{e.message}"
|
123
|
+
end
|
124
|
+
|
125
|
+
def upsert_log_to_mongo_log_group(collection_name, document)
|
126
|
+
existing_document = find(collection_name, { ms: document[:ms] }).first
|
127
|
+
document.delete(:created_at) if existing_document
|
128
|
+
result = update_log_group(collection_name, { ms: document[:ms] }, { '$set' => document }, upsert: true)
|
129
|
+
|
130
|
+
if result&.upserted_count&.positive?
|
131
|
+
puts "Inserted new document for ms: #{document[:ms]}"
|
132
|
+
else
|
133
|
+
puts "Updated document for ms: #{document[:ms]}"
|
134
|
+
end
|
135
|
+
rescue StandardError => e
|
136
|
+
puts "Error upserting into MongoDB: #{e.message}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def fetch_log_groups_from_mongo
|
140
|
+
log_groups = {}
|
141
|
+
find('log_group_lambda', {}).each do |doc|
|
142
|
+
next unless doc['ms'] && doc['log_groups'].is_a?(Array)
|
143
|
+
log_groups[doc['ms']] = doc['log_groups']
|
144
|
+
end
|
145
|
+
log_groups
|
146
|
+
end
|
147
|
+
|
148
|
+
def get_last_run_from_mongo(collection_name, ms)
|
149
|
+
collection = find_sort(collection_name, { ms: ms }, { last_run: -1 }, 1).first
|
150
|
+
collection ? collection[:last_run] : nil
|
151
|
+
rescue StandardError => e
|
152
|
+
puts "Error fetching last_run: #{e.message}"
|
153
|
+
nil
|
154
|
+
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def build_connection_string
|
159
|
+
user = ENV['USER'] || ENV['MONGODB_USER']
|
160
|
+
password = ENV['PASSWORD'] || ENV['MONGODB_PASSWORD']
|
161
|
+
host = ENV['HOST'] || ENV['MONGODB_HOST']
|
162
|
+
database = ENV['DATABASE'] || ENV['MONGODB_DATABASE']
|
163
|
+
|
164
|
+
"mongodb+srv://#{user}:#{password}@#{host}/#{database}?retryWrites=true&w=majority&readPreference=primaryPreferred"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative 'functionator/version'
|
2
|
+
require_relative 'functionator/mongodb/client'
|
3
|
+
|
4
|
+
module Functionator
|
5
|
+
# Entry point for the Functionator gem
|
6
|
+
# A multi-purpose library with various functionalities
|
7
|
+
|
8
|
+
# MongoDB functionality
|
9
|
+
def self.mongodb
|
10
|
+
Functionator::MongoDB::Client.instance
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: functionator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kaique Leonardo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mongo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Functionator - A Ruby gem that provides a MongoDB client factory with
|
70
|
+
singleton pattern and common database operations like insert, find, update, and
|
71
|
+
aggregation queries.
|
72
|
+
email:
|
73
|
+
- kaique.silva@terceiros-sky.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- functionator.gemspec
|
81
|
+
- lib/functionator.rb
|
82
|
+
- lib/functionator/mongodb/client.rb
|
83
|
+
- lib/functionator/version.rb
|
84
|
+
- lib/mongodb_factory.rb
|
85
|
+
- lib/mongodb_factory/client.rb
|
86
|
+
- lib/mongodb_factory/version.rb
|
87
|
+
homepage: https://github.com/seuusuario/functionator
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.4.19
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: A MongoDB client factory with common operations
|
110
|
+
test_files: []
|