Module: Gapic::Helpers::NamespaceHelper
- Included in:
- Presenters::FieldPresenter, Presenters::FilePresenter, Presenters::GemPresenter, Presenters::MessagePresenter, Presenters::Method::ComputePaginationInfo, Presenters::MethodPresenter, Presenters::PackagePresenter, Presenters::ServicePresenter, Presenters::ServiceRestPresenter
- Defined in:
- lib/gapic/helpers/namespace_helper.rb
Overview
Helpers related to generating ruby namespaces
Instance Method Summary collapse
-
#ensure_absolute_namespace(namespace) ⇒ Object
Returns the given namespace, ensuring double colons are prepended.
-
#fix_namespace(api, namespace) ⇒ Object
Corrects a namespace by replacing known bad values with good values.
-
#ruby_namespace(api, address) ⇒ Object
Looks up the ruby_package for a dot-separated address string to a new string and creates the corrected Ruby namespace.
-
#ruby_namespace_for_address(address) ⇒ Object
Converts an array or dot-separated address string to a new string with Ruby double-semicolon separators.
Instance Method Details
#ensure_absolute_namespace(namespace) ⇒ Object
Returns the given namespace, ensuring double colons are prepended
47 48 49 |
# File 'lib/gapic/helpers/namespace_helper.rb', line 47 def ensure_absolute_namespace namespace namespace.start_with?("::") ? namespace : "::#{namespace}" end |
#fix_namespace(api, namespace) ⇒ Object
Corrects a namespace by replacing known bad values with good values.
53 54 55 |
# File 'lib/gapic/helpers/namespace_helper.rb', line 53 def fix_namespace api, namespace namespace.split("::").map { |node| api.fix_namespace node }.join("::") end |
#ruby_namespace(api, address) ⇒ Object
Looks up the ruby_package for a dot-separated address string to a new string and creates the corrected Ruby namespace
28 29 30 31 32 33 34 |
# File 'lib/gapic/helpers/namespace_helper.rb', line 28 def ruby_namespace api, address file = api.file_for address address = address.dup address[file.package] = file.ruby_package if file.ruby_package.present? namespace = ruby_namespace_for_address address fix_namespace api, namespace end |
#ruby_namespace_for_address(address) ⇒ Object
Converts an array or dot-separated address string to a new string with Ruby double-semicolon separators.
39 40 41 42 |
# File 'lib/gapic/helpers/namespace_helper.rb', line 39 def ruby_namespace_for_address address address = address.split "." if address.is_a? String ensure_absolute_namespace address.reject(&:empty?).map(&:camelize).join("::") end |