Class: Workarea::Configuration::MongoidClient
- Inherits:
-
Object
- Object
- Workarea::Configuration::MongoidClient
- Defined in:
- lib/workarea/configuration/mongoid_client.rb
Instance Method Summary collapse
- #database ⇒ Object
- #hosts ⇒ Object
-
#initialize(name = nil) ⇒ MongoidClient
constructor
A new instance of MongoidClient.
- #options ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ MongoidClient
Returns a new instance of MongoidClient.
4 5 6 7 |
# File 'lib/workarea/configuration/mongoid_client.rb', line 4 def initialize(name = nil) @name = name @default = MongoidClient.new unless name.nil? end |
Instance Method Details
#database ⇒ Object
17 18 19 |
# File 'lib/workarea/configuration/mongoid_client.rb', line 17 def database "#{Workarea.config.site_name.systemize}_#{Rails.env}" end |
#hosts ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/workarea/configuration/mongoid_client.rb', line 21 def hosts env_hosts = ENV.select { |k| k =~ /^#{env_key}_HOST(?:_\d+)?$/ } .map(&:last) .reject(&:blank?) env_hosts.presence || @default&.hosts || ['localhost:27017'] end |
#options ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/workarea/configuration/mongoid_client.rb', line 30 def JSON.parse(ENV["#{env_key}_OPTIONS"].presence || '{}') .deep_symbolize_keys .reverse_merge(@default&. || {}) .reverse_merge(max_pool_size: max_pool_size) rescue JSON::ParserError {} end |
#to_h ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/workarea/configuration/mongoid_client.rb', line 9 def to_h { database: database, hosts: hosts, options: } end |