module Google::Apis::Generator::NameHelpers
Methods for validating & normalizing symbols
Constants
- KEYWORDS
- PLURAL_METHODS
Public Instance Methods
constantize_scope(url)
click to toggle source
Converts a scope string into a ruby constant @param [String] url
Url to convert
@return [String]
# File lib/google/apis/generator/helpers.rb, line 66 def constantize_scope(url) scope = Addressable::URI.parse(url).path[1..-1].upcase.gsub(/\W/, '_') scope = 'AUTH_SCOPE' if scope.nil? || scope.empty? scope end
keyword?(name)
click to toggle source
Check to see if the name is a ruby keyword @return [Boolean]
# File lib/google/apis/generator/helpers.rb, line 26 def keyword?(name) KEYWORDS.include?(name) end
normalize_param_name(name)
click to toggle source
Convert a parameter name to ruby conventions @param [String] name @return [String] updated param name
# File lib/google/apis/generator/helpers.rb, line 39 def normalize_param_name(name) name = ActiveSupport::Inflector.underscore(name.gsub(/\W/, '_')) if reserved?(name) logger.warn { sprintf('Found reserved keyword \%1$s\', name) } name += '_' logger.warn { sprintf('Changed to \%1$s\', name) } end name end
normalize_property_name(name)
click to toggle source
Convert a property name to ruby conventions @param [String] name @return [String]
# File lib/google/apis/generator/helpers.rb, line 52 def normalize_property_name(name) name = ActiveSupport::Inflector.underscore(name.gsub(/\W/, '_')) if object_method?(name) logger.warn { sprintf('Found reserved property \%1$s\', name) } name += '_prop' logger.warn { sprintf('Changed to \%1$s\', name) } end name end
object_method?(name)
click to toggle source
Check to see if the method already exists on ruby objects @return [Boolean]
# File lib/google/apis/generator/helpers.rb, line 32 def object_method?(name) Object.new.respond_to?(name) end
pluralize_method?(method_name)
click to toggle source
Check to see if the method name should be plauralized @return [Boolean]
# File lib/google/apis/generator/helpers.rb, line 14 def pluralize_method?(method_name) PLURAL_METHODS.include?(method_name) end
reserved?(name)
click to toggle source
Check to see if the method is either a keyword or built-in method on object @return [Boolean]
# File lib/google/apis/generator/helpers.rb, line 20 def reserved?(name) keyword?(name) || object_method?(name) end