Sha256: e65ba156b1c2bae0fbf21bf3701423b4673258d0e8d3cf94cf37303459183721

Contents?: true

Size: 1.59 KB

Versions: 24

Compression:

Stored size: 1.59 KB

Contents

require_relative '../helpers/camel_case'
require_relative '../helpers/path'

module Hubspot
  module Discovery
    module BaseModuleClient
      attr_reader :params

      def initialize(params)
        @params = params
        define_methods
      end
        
      def base_module
        self.class.name.gsub(/(.*)::.*/, '\1')
      end
  
      def api_modules
        []
      end
  
      def api_classes
        []
      end

      private
  
      def define_methods
        define_modules_methods
        define_classes_methods
      end
  
      def define_modules_methods
        api_modules.each do |api_module|
          self.class.define_method(api_module) do
            require_with_mapping "#{discovery_module_path}/#{__method__.to_s}/client"
            class_name = "#{base_module}::#{Hubspot::Helpers::CamelCase.new.format(__method__.to_s)}::Client"
            Kernel.const_get(class_name).new(params)
          end
        end
      end
        
      def define_classes_methods
        api_classes.each do |api_class|
          self.class.define_method("#{api_class}_api") do
            require_with_mapping "#{discovery_module_path}/api/#{__method__.to_s}"
            class_name = "#{base_module}::#{Hubspot::Helpers::CamelCase.new.format(__method__.to_s)}"
            Kernel.const_get(class_name).new(params)
          end
        end
      end

      def discovery_module_path
        @discovery_module_path ||= Hubspot::Helpers::Path.new.format(base_module)
      end

      def require_with_mapping(path)
        Hubspot::Helpers::Path.new.require_with_mapping(path)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
hubspot-api-client-16.0.0 lib/hubspot/discovery/base_module_client.rb
hubspot-api-client-15.0.2 lib/hubspot/discovery/base_module_client.rb
hubspot-api-client-15.0.1 lib/hubspot/discovery/base_module_client.rb
hubspot-api-client-15.0.0 lib/hubspot/discovery/base_module_client.rb