class HaveAPI::GoClient::Parameters::Association

Attributes

go_type[R]

@return [String]

go_value_id[R]

@return [String]

go_value_label[R]

@return [String]

parameter[R]

@return [Parameter]

resource[R]

@return [Resource]

Public Class Methods

new(param, desc) click to toggle source
# File lib/haveapi/go_client/parameters/association.rb, line 22
def initialize(param, desc)
  @parameter = param
  @resource = find_resource(desc[:resource])
  @go_type = resource.actions.detect { |a| a.name == 'show' }.output.go_type
  @go_value_id = camelize(desc[:value_id])
  @go_value_label = camelize(desc[:value_label])
end

Protected Instance Methods

find_resource(path) click to toggle source
# File lib/haveapi/go_client/parameters/association.rb, line 31
def find_resource(path)
  root = parameter.io.action.resource.api_version
  path = path.clone

  loop do
    name = path.shift
    resource = root.resources.detect { |r| r.name == name }

    if resource.nil?
      fail "associated resource '#{name}' not found in "+
            (root.is_a?(ApiVersion) ? 'root' : root.resource_path.map(&:name).join('.'))

    elsif path.empty?
      return resource

    else
      root = resource
    end
  end

  fail 'programming error'
end