mardi 28 juin 2022

how to Include a module from app/lib folder

I am getting an error while trying to load a class from module which is present in app/lib folder.

I had made changes according to it

Controller

class SchemasController < ApplicationController
  # include Schemas
  # require './app/lib/api'
  include Operator
end

class under module which I have to include:

# frozen_string_literal: true

module API
  module AnalyticsQueryBuilderMetadataService
    class Operator
      @base_uri = ServiceConfig[:analytics_query_builder_metadata_service_uri]

      def self.where(params = {})
        response = API::Connection.connect_with_oauth1a(@base_uri).get('operators', params)

        response.body
      end
    end
  end
end

application.rb:

require_relative "boot"


# Pick the frameworks you want:
require 'action_controller/railtie'
require 'active_job/railtie'
require 'action_cable/engine'
require 'action_mailer/railtie'


# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module AnalyticsQueryBuilder
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 7.0
    config.autoload_paths += %W(#{config.root}/lib)
    # config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += Dir["#{config.root}/lib/**/"]
    config.before_configuration do
      env_file = File.join(Rails.root, 'config', 'local_env.yml')
      if File.exist?(env_file)
        YAML.safe_load(File.open(env_file)).each do |key, value|
          ENV[key.to_s] = value
        end
      end
    end
    Rails.logger = Logger.new($stdout)

    config.exceptions_app = routes
 
  end
end

The structure of file:

https://i.stack.imgur.com/gM16x.png

How to include it in Controller

Aucun commentaire:

Enregistrer un commentaire