wonder_oracle_database 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2d0e4aa95d03288b958cdfaa0bc48ecf9962849c8b3b95c88512b19e5985cee
4
- data.tar.gz: 34a17a098a2f3a45c27168eeab20fd92590b2a14f229d2e9e7c5ff678bef9fc1
3
+ metadata.gz: 687f8c858046c82fd21cf982a64172296296da25ae57416d72ada2e9d3fd8a00
4
+ data.tar.gz: 5bc9e5ba30947223e6c01270e7161b4b1e2849a24c83cc514361c832a631318c
5
5
  SHA512:
6
- metadata.gz: 7327d527df59e75a9a80013a0097538c5768a4ccbb5c7320a45f17ffccd3eff6f927d68ed96c1504f9bbbf254be00b8b62f6cd142d2cebe3ff9e53e6b9f7e9da
7
- data.tar.gz: 1a7c5c66284289f79dcf567990cde0ab86fc56dd5d9f5b4a6706b832c22e00d1e08b5f5c618c940f8f7a62845a3188a434cc4b6eebff641d72e0470850d78752
6
+ metadata.gz: 935ee59d389ed96d8f24632d629b579e1358229479df3dd0ce55024194766f7a1819a5a0a241adcdf5d7cffc012f8e7097df838001887d86a64e8541c5a7b506
7
+ data.tar.gz: b71536c7244e389393d8b1c12326c98b56a1e4393d082528de3494f3e7e32e19eef20a7797270e6194d31657e84be2d3fea28523803575e96c8fa799dd3aed95
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wonder_oracle_database (1.0.0)
4
+ wonder_oracle_database (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -61,4 +61,4 @@ DEPENDENCIES
61
61
  wonder_oracle_database!
62
62
 
63
63
  BUNDLED WITH
64
- 1.16.1
64
+ 1.16.2
data/README.md CHANGED
@@ -45,4 +45,4 @@ production:
45
45
  <<: *default
46
46
  ```
47
47
 
48
- O WonderOracleDatabase uitliza a variável de ambiente `W_HOST_DB_SERVER` para buscar os dados.
48
+ O WonderOracleDatabase uitliza a variável de ambiente `DATABASE_URL`ou `W_HOST_DB_SERVER` para buscar os dados.
@@ -1,3 +1,3 @@
1
1
  module WonderOracleDatabase
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -1,58 +1,80 @@
1
1
  require 'wonder_oracle_database/version'
2
2
 
3
3
  module WonderOracleDatabase
4
- def self.present?
5
- !environment.nil?
6
- end
4
+ class << self
5
+ def variable_candidates
6
+ %w[
7
+ DATABASE_URL
8
+ W_HOST_DB_SERVER
9
+ ]
10
+ end
7
11
 
8
- def self.shared?
9
- !ENV['RAILS_ENV'] == 'test' && present? && load.try(:[], :shared)
10
- end
12
+ def present?
13
+ !environment.nil?
14
+ end
11
15
 
12
- def self.load
13
- parsed_env if present?
14
- end
16
+ def test?
17
+ ENV['RAILS_ENV'].to_s.upcase.eql?('TEST')
18
+ end
15
19
 
16
- def self.environment
17
- ENV['W_HOST_DB_SERVER']
18
- end
20
+ def shared?
21
+ !test? && present? && !load.nil? && load[:shared]
22
+ end
19
23
 
20
- def self.parsed_env
21
- match = parse_obfuscated_variable.match(/^(\w+)\/(\w+)@(.+)$/)
24
+ def load
25
+ parsed_env if present?
26
+ end
22
27
 
23
- return invalid_variable_error unless match
28
+ def environment
29
+ result = nil
24
30
 
25
- usuario, senha, banco = match.captures
31
+ variable_candidates.each do |e|
32
+ next if result
26
33
 
27
- {
28
- username: usuario,
29
- password: senha,
30
- database: banco,
31
- adapter: 'oracle_enhanced',
32
- shared: true
33
- }
34
- end
34
+ result = ENV[e]
35
+ end
35
36
 
36
- def self.parse_obfuscated_variable
37
- environment =~ /^(\w+)\/(\w+)@(.+)$/ ? environment : [environment].pack('H*') # converte de hex para decimal
38
- .reverse # inverte a string
39
- .split('') # cria um array de caracteres
40
- .collect { |c| (c.chr.ord - 1).chr } # converte a cadeia de caracteres obfuscados pra seus valores verdadeiros
41
- .join # junta o array em uma string
42
- end
37
+ result
38
+ end
43
39
 
44
- def self.obfuscate_variable
45
- parse_obfuscated_variable.split('') # cria um array de caracteres
46
- .collect { |c| (c.chr.ord + 1).chr } # converte a cadeia de caracteres para seus valores obfuscados
47
- .join # junta o array em uma string
48
- .reverse # inverte a string
49
- .unpack('H*') # converte pra array de hexadecimais
50
- .join # junta o array em uma string
51
- end
40
+ def parsed_env
41
+ match = parse_obfuscated_variable.match(/^(\w+)\/(\w+)@(.+)$/)
42
+
43
+ return invalid_variable_error unless match
44
+
45
+ usuario, senha, banco = match.captures
46
+
47
+ {
48
+ username: usuario,
49
+ password: senha,
50
+ database: banco,
51
+ adapter: 'oracle_enhanced',
52
+ shared: true,
53
+ encoding: 'unicode'
54
+ }
55
+ end
56
+
57
+ def parse_obfuscated_variable
58
+ environment =~ /^(\w+)\/(\w+)@(.+)$/ ? environment : [environment].pack('H*') # converte de hex para decimal
59
+ .reverse # inverte a string
60
+ .split('') # cria um array de caracteres
61
+ .collect { |c| (c.chr.ord - 1).chr } # converte a cadeia de caracteres obfuscados pra seus valores verdadeiros
62
+ .join # junta o array em uma string
63
+ end
64
+
65
+ def obfuscate_variable
66
+ parse_obfuscated_variable.split('') # cria um array de caracteres
67
+ .collect { |c| (c.chr.ord + 1).chr } # converte a cadeia de caracteres para seus valores obfuscados
68
+ .join # junta o array em uma string
69
+ .reverse # inverte a string
70
+ .unpack('H*') # converte pra array de hexadecimais
71
+ .join # junta o array em uma string
72
+ end
52
73
 
53
- def self.invalid_variable_error
54
- puts "W_HOST_DB_SERVER inválida: deve ser usuario/senha@[ip/]banco ou obfuscada, valor da variável: #{environment}."
74
+ def invalid_variable_error
75
+ puts "W_HOST_DB_SERVER inválida: deve ser usuario/senha@[ip/]banco ou obfuscada, valor da variável: #{environment}."
55
76
 
56
- false
77
+ false
78
+ end
57
79
  end
58
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wonder_oracle_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wonder Sistemas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.7.6
124
+ rubygems_version: 2.7.7
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Wonder Sistemas' shared oracle database config for Rails.