Class: Gapic::Presenters::WrapperGemPresenter

Inherits:
CloudGemPresenter show all
Defined in:
lib/gapic/presenters/wrapper_gem_presenter.rb

Overview

A presenter for wrapper gems.

Instance Method Summary collapse

Methods inherited from CloudGemPresenter

#cloud_env_prefix, #description, #generator_args_for_metadata, #has_wrapper?, #library_documentation_url, #license_name, #readme_description, #wrapper_name

Instance Method Details

#default_versionObject



100
101
102
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 100

def default_version
  version_dependencies.first&.first
end

#default_versioned_gemObject



104
105
106
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 104

def default_versioned_gem
  versioned_gems.first
end

#dependenciesObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 108

def dependencies
  @dependencies ||= begin
    deps = { "google-cloud-core" => "~> 1.6" }
    version_dependencies.each do |version, requirement|
      # For pre-release dependencies on versioned clients, support both
      # 0.x and 1.x versions to ease the transition to 1.0 (GA) releases
      # for those dependencies. (Note the 0.x->1.0 transition is
      # generally not breaking.)
      deps["#{name}-#{version}"] =
        if requirement.start_with? "0."
          [">= #{requirement}", "< 2.a"]
        else
          "~> #{requirement}"
        end
    end
    extra_deps = gem_config_dependencies
    deps.merge! extra_deps if extra_deps
    deps
  end
end


135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 135

def docs_link version: nil, class_name: nil, text: nil
  gem_name = version ? "#{name}-#{version}" : name
  base_url = "https://googleapis.dev/ruby/#{gem_name}/latest"
  if class_name
    path = namespace.gsub "::", "/"
    path = "#{path}/#{version.capitalize}" if version
    class_path = class_name.gsub "::", "/"
    text ||= namespaced_class class_name, version: version
    return "[#{text}](#{base_url}/#{path}/#{class_path}.html)"
  end
  "[#{text || name}](#{base_url})"
end

#entrypoint_requireObject



26
27
28
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 26

def entrypoint_require
  namespace_require
end

#extra_filesObject



81
82
83
84
85
86
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 81

def extra_files
  files = ["README.md", "LICENSE.md", ".yardopts"]
  files.insert 1, "AUTHENTICATION.md" unless generic_endpoint?
  files.append "MIGRATING.md" if migration?
  files
end

#factory_method_suffixObject



88
89
90
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 88

def factory_method_suffix
  gem_config(:factory_method_suffix).to_s
end

#google_cloud_short_nameObject



129
130
131
132
133
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 129

def google_cloud_short_name
  m = /^google-cloud-(.*)$/.match name
  return nil unless m
  m[1].tr "-", "_"
end

#helpers_requireObject



45
46
47
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 45

def helpers_require
  "#{namespace_require}/helpers"
end

#main_directory_nameObject



41
42
43
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 41

def main_directory_name
  namespace_require.split("/").last
end

#migration?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 77

def migration?
  migration_version ? true : false
end

#migration_versionObject



61
62
63
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 61

def migration_version
  gem_config :migration_version
end

#namespace_file_pathObject



49
50
51
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 49

def namespace_file_path
  "#{namespace_require}.rb"
end

#namespace_requireObject



37
38
39
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 37

def namespace_require
  ruby_file_path @api, namespace
end

#namespaced_class(name, version: nil) ⇒ Object



148
149
150
151
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 148

def namespaced_class name, version: nil
  base = version ? "#{namespace}::#{version.capitalize}" : namespace
  "#{base}::#{name}"
end

#needs_default_config_block?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 57

def needs_default_config_block?
  needs_entrypoint? && !google_cloud_short_name.nil?
end

#needs_entrypoint?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 53

def needs_entrypoint?
  name != namespace_require
end

#pre_migration_versionObject

A description of the versions prior to the migration version. Could be “a.x” if the migration version is 1.0 or later, otherwise falls back to “pre-a.b”.



68
69
70
71
72
73
74
75
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 68

def pre_migration_version
  match = /^(\d)+\.0/.match migration_version.to_s
  if match
    major = match[1].to_i
    return "#{major - 1}.x" if major.positive?
  end
  "pre-#{migration_version}"
end

#servicesObject



30
31
32
33
34
35
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 30

def services
  @services ||= begin
    files = @api.generate_files
    files.map(&:services).flatten.map { |s| WrapperServicePresenter.new self, @api, s }
  end
end

#version_dependenciesObject



92
93
94
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 92

def version_dependencies
  gem_config(:version_dependencies).to_s.split(";").map { |str| str.split ":" }
end

#versioned_gemsObject



96
97
98
# File 'lib/gapic/presenters/wrapper_gem_presenter.rb', line 96

def versioned_gems
  version_dependencies.map { |version, _requirement| "#{name}-#{version}" }.sort
end