Module: AuxiliaryRails::Application::Service

Defined in:
lib/auxiliary_rails/application/service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Raises:

  • (AuxiliaryRails::Error)


7
8
9
10
# File 'lib/auxiliary_rails/application/service.rb', line 7

def self.included(klass)
  raise AuxiliaryRails::Error,
    "Use `extend` insted of `include` for #{self} in #{klass}"
end

Instance Method Details

#configObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

Raises:

  • (AuxiliaryRails::Error)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/auxiliary_rails/application/service.rb', line 13

def config
  return @config if @config.present?

  # load from constant
  if const_defined?(:CONFIG)
    return @config = ActiveSupport::OrderedOptions.new.update(const_get(:CONFIG))
  end

  service_name = name.underscore

  # load from service config file
  if Rails.root.join("config/services/#{service_name}.yml").exist?
    return @config = Rails.application.config_for("services/#{service_name}")
  end

  # load from application config
  if Object.const_defined?(:Config) && Config.respond_to?(:const_name)
    app_config = Object.const_get(Config.const_name)
    if app_config.dig(:services, service_name).present?
      return @config = app_config[:services][service_name]
    end
  end

  raise AuxiliaryRails::Error,
    "Unable to find suitable config for #{name} module"
end