Module: Google::Ads::GoogleAds::Utils
- Defined in:
- lib/google/ads/google_ads/utils/string_utils.rb,
lib/google/ads/google_ads/utils/path_lookup_definer.rb,
lib/google/ads/google_ads/utils/v15/path_lookup_util.rb,
lib/google/ads/google_ads/utils/v16/path_lookup_util.rb,
lib/google/ads/google_ads/utils/v17/path_lookup_util.rb,
lib/google/ads/google_ads/utils/build_path_lookup_class.rb
Defined Under Namespace
Modules: V15, V16, V17 Classes: PathLookupDefiner
Class Method Summary collapse
- .build_path_lookup_class(version) ⇒ Object
-
.camelize(string) ⇒ Object
Takes a string and converts it from snake case to camel case.
- .underscore(string) ⇒ Object
Class Method Details
.build_path_lookup_class(version) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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| return false if @non_path_methods.include?(name) return true if @lookups.include?(name) require "google/ads/google_ads/#{version}/services/google_ads_service/paths" mod = Kernel.const_get("Google::Ads::GoogleAds::#{version.upcase}::Services::GoogleAdsService::Paths") unless mod.respond_to?("#{name}_path") # A handful of path helpers like `google_ads_field_path` are not included in `google_ads_service/paths` require "google/ads/google_ads/#{version}/services/#{name}_service/paths" end @lookups.add(name) return true rescue LoadError @non_path_methods.add(name) return false end end end |
.camelize(string) ⇒ Object
Takes a string and converts it from snake case to camel case. e.g: foo_service becomes FooService
25 26 27 |
# 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) ⇒ Object
29 30 31 32 33 34 |
# 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 |