bug_bunny 0.2.5 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f97718fff3161c0caa40bac2d6b5caa6e4116a9c2aa7b5b28ff914204def6620
4
- data.tar.gz: 25ed25993112d98da6bb1746e171f22ffafb2cd0d704459be951ff5acfe0dd73
3
+ metadata.gz: 31500216aa7e9c86af5f6ec88557ee0aa2f242bffd4d94ab09d9ebf80fcb8e68
4
+ data.tar.gz: bab1c226bcad2e1e4b890cdf48ee88f10a9d801ccf1e39a1473881b91f5de57f
5
5
  SHA512:
6
- metadata.gz: 5f9cc8c2591083ddad646c832faaeada4bda39734522fea45a1ade1115ef37a8d79a536e7a1dc743b4f6d29fe8f8f3a88a8fddae2dd902a6c439de28adca942d
7
- data.tar.gz: a2f7b56c4fddb35f023fe3eb2d42b22b00cf8206b0f5201f3c9ae2927c29243ce46ea89ff3afab9d2f8b37797831edab73405470e1426a35a39bf05b8cf7fc1b
6
+ metadata.gz: 1df32f70805935baf2f3029955701b65d83caf330ee4f12f02f95267c880337d4dadcdfe086fe1990fb9de0e917a1bc8fd86feb4c48bcf8d194f8aee0f92bf2e
7
+ data.tar.gz: 1b926db41aad313ae52542933c5932d2237451eeac398d5841315419b061afb16c37035687d1fb373817fece679b74ccb1d38601a0307d5fb63c087e24b10f6a
@@ -0,0 +1,11 @@
1
+ module BugBunny
2
+ class Config
3
+ # getter y setter para cada propiedad.
4
+ attr_accessor :user, :pass, :host, :virtual_host, :logger, :log_level
5
+
6
+ # Método para generar la URL de conexión
7
+ def url
8
+ "amqp://#{user}:#{pass}@#{host}/#{virtual_host}"
9
+ end
10
+ end
11
+ end
@@ -68,8 +68,6 @@ module BugBunny
68
68
  # status = :open, :connected, :connecting,
69
69
  # :closing, :disconnected, :not_connected, :closed
70
70
  def create_connection
71
- options = {}
72
-
73
71
  # if WisproUtils::Config.defaults.use_tls
74
72
  # path = (Rails.root.join('private', 'certs') rescue './private/certs')
75
73
  # options.merge!(tls: true,
@@ -80,28 +78,27 @@ module BugBunny
80
78
  # tls_key: "#{path}/key.pem",
81
79
  # tls_ca_certificates: ["#{path}/ca.pem"])
82
80
  # end
81
+ options = {}
83
82
 
84
- logger&.debug('Stablish new connection to rabbit')
85
- logger&.debug("amqp://#{ENV['RABBIT_USER']}:" \
86
- "#{ENV['RABBIT_PASS']}@#{ENV['RABBIT_HOST']}" \
87
- "/#{ENV['RABBIT_VIRTUAL_HOST']}")
83
+ raise "Need user" if BugBunny.configuration.user.blank?
84
+ raise "Need pass" if BugBunny.configuration.pass.blank?
85
+ raise "Need host" if BugBunny.configuration.host.blank?
88
86
 
87
+ bunny_logger = BugBunny.configuration.logger || ::Logger.new('./log/bunny.log', 7, 10485760)
88
+ bunny_logger.level = BugBunny.configuration.log_level || ::Logger::INFO
89
89
 
90
- bunny_logger = ::Logger.new('./log/bunny.log', 7, 10485760)
91
- bunny_logger.level = ::Logger::DEBUG
92
90
  options.merge!(
93
- heartbeat_interval: 20, # 20.seconds per connection
91
+ heartbeat_interval: 20, # 20.seconds per connection
94
92
  logger: bunny_logger,
95
93
  # Override bunny client_propierties
96
- client_properties: { product: identifier, platform: ''}
94
+ client_properties: { product: identifier, platform: '' }
97
95
  )
98
96
 
99
- rabbit_conn = Bunny.new("amqp://#{ENV['RABBIT_USER']}" \
100
- ":#{ENV['RABBIT_PASS']}@"\
101
- "#{ENV['RABBIT_HOST']}/"\
102
- "#{ENV['RABBIT_VIRTUAL_HOST']}",
103
- options)
104
- rabbit_conn.start
97
+ logger&.debug('Stablish new connection to rabbit')
98
+ logger&.debug(BugBunny.configuration.url)
99
+
100
+ Bunny.new(BugBunny.configuration.url, options).start
101
+
105
102
  logger&.debug("New status connection: #{rabbit_conn.status}")
106
103
 
107
104
  self.connection = rabbit_conn
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BugBunny
4
- VERSION = "0.2.5"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/bug_bunny.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'bunny'
4
4
  require_relative "bug_bunny/version"
5
+ require_relative "bug_bunny/config"
5
6
  require_relative "bug_bunny/adapter"
6
7
  require_relative "bug_bunny/controller"
7
8
  require_relative "bug_bunny/exception"
@@ -18,4 +19,16 @@ if defined? ::Rails::Railtie
18
19
  end
19
20
 
20
21
  module BugBunny
22
+ class << self
23
+ # Aquí guardaremos la instancia de la configuración
24
+ def configuration
25
+ @configuration ||= BugBunny::Config.new
26
+ end
27
+
28
+ # Este es el método que usaremos para configurar.
29
+ # Recibe un bloque de código y le pasa el objeto de configuración.
30
+ def configure
31
+ yield(configuration) if block_given?
32
+ end
33
+ end
21
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bug_bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gabix
@@ -50,6 +50,7 @@ files:
50
50
  - Rakefile
51
51
  - lib/bug_bunny.rb
52
52
  - lib/bug_bunny/adapter.rb
53
+ - lib/bug_bunny/config.rb
53
54
  - lib/bug_bunny/controller.rb
54
55
  - lib/bug_bunny/exception.rb
55
56
  - lib/bug_bunny/helpers.rb