module Google::Ads::GoogleAds::Utils

Public Class Methods

build_path_lookup_class(version) click to toggle source
Calls superclass method
# File lib/google/ads/google_ads/utils/build_path_lookup_class.rb, line 26
def self.build_path_lookup_class(version)
  Class.new do
    define_method(:initialize) do
      @lookups = Set.new
      @non_path_methods = Set.new
    end

    define_method(:respond_to_missing?) do |name, include_private=false|
      validate_method_name(name) || super
    end

    define_method(:method_missing) do |name, *args, **kwargs|
      raise ArgumentError, "unknown path type #{name}" unless validate_method_name(name)
      if args.any? { |arg| arg.nil? }
        raise ArgumentError, "invalid args for #{name}: #{args.inspect}"
      end

      define_lookup_method(name, version)
      send(name, *args, **kwargs)
    end

    define_method(:define_lookup_method) do |name, version|
      Utils::PathLookupDefiner.new(self, name).call(version)
    end

    define_method(:validate_method_name) do |name|
      if !@non_path_methods.include?(name)
        return true if @lookups.include?(name)
        begin
          require "google/ads/google_ads/#{version}/services/#{name}_service/paths"
          @lookups.add(name)
          return true
        rescue LoadError => e
          @non_path_methods.add(name)
        end
        return false
      end
    end
  end
end
camelize(string) click to toggle source

Takes a string and converts it from snake case to camel case. e.g: foo_service becomes FooService

# File lib/google/ads/google_ads/utils/string_utils.rb, line 25
def self.camelize(string)
  string.to_str.split("_").map(&:capitalize).join
end
underscore(string) click to toggle source
# File lib/google/ads/google_ads/utils/string_utils.rb, line 29
def self.underscore(string)
  string.to_str.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end