Class: Gapic::Presenters::ResourcePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/presenters/resource_presenter.rb

Overview

A presenter for proto resources.

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ ResourcePresenter

Returns a new instance of ResourcePresenter.

Parameters:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gapic/presenters/resource_presenter.rb', line 28

def initialize resource
  @resource = resource

  @patterns = resource.pattern.map do |template|
    segments = Gapic::PathTemplate.parse template
    OpenStruct.new(
      template:    template,
      segments:    segments,
      arguments:   arguments_for(segments),
      path_string: path_string_for(segments)
    )
  end

  # Keep only patterns that can be used to create path helpers
  @patterns.reject! do |pattern|
    named_arg_patterns?(pattern.segments) || positional_args?(pattern.segments)
  end
end

Instance Method Details

#name ⇒ Object



47
48
49
# File 'lib/gapic/presenters/resource_presenter.rb', line 47

def name
  @resource.type.split("/").delete_if(&:empty?).last
end

#path_helper ⇒ Object



59
60
61
# File 'lib/gapic/presenters/resource_presenter.rb', line 59

def path_helper
  "#{ActiveSupport::Inflector.underscore name}_path"
end

#patterns ⇒ Object



55
56
57
# File 'lib/gapic/presenters/resource_presenter.rb', line 55

def patterns
  @patterns
end

#type ⇒ Object



51
52
53
# File 'lib/gapic/presenters/resource_presenter.rb', line 51

def type
  @resource.type
end