class LabClient::Klass

Common Configuration for all Class Helpers

Attributes

client[R]
response[R]

Public Class Methods

date_time_attrs(list) click to toggle source

Define a list of DateTime Attributes

# File lib/labclient/klass.rb, line 132
def self.date_time_attrs(list)
  list.each do |kind|
    define_method(kind) do
      DateTime.parse @table[kind] if has? kind
    end
  end
end
new(hash = nil, response = nil, client = nil) click to toggle source

rubocop:disable Lint/MissingSuper

# File lib/labclient/klass.rb, line 109
def initialize(hash = nil, response = nil, client = nil)
  @client = client
  @response = response

  @table = {}
  hash&.each_pair do |k, v|
    k = k.to_sym
    @table[k] = v
  end
end
user_attrs(list) click to toggle source

Define a list of LabClient::User Attributes

# File lib/labclient/klass.rb, line 141
def self.user_attrs(list)
  list.each do |kind|
    define_method(kind) do
      User.new(@table[kind], response, client) if has? kind
    end
  end
end

Public Instance Methods

api_methods() click to toggle source

Documented API Methods

# File lib/labclient/klass.rb, line 43
def api_methods
  docs = LabClient::Docs.docs.dig(group_name, 'Reference')

  unless docs
    puts 'No Available Help'
    return false
  end

  LabClient::Docs.docs.dig(group_name, 'Reference').map do |doc|
    doc[:options].map do |opt|
      opt[:name]
    end
  end.flatten.sort
end
collect_group_id(position = 1)
Alias for: collect_project_id
collect_project_id(position = 1) click to toggle source

TODO: Combine all of these?

# File lib/labclient/klass.rb, line 63
def collect_project_id(position = 1)
  # Check if Path / Pagination will be blank
  if response.path.nil?
    response.request.base_url.split(@client.base_url, 2)[position]
  else
    CGI.unescape response.path.split('/')[position]
  end
end
Also aliased as: collect_group_id, collect_user_id
collect_release_id(position = 3) click to toggle source
# File lib/labclient/klass.rb, line 75
def collect_release_id(position = 3)
  response.path.split('/')[position]
end
collect_repository_id(position = 4) click to toggle source
# File lib/labclient/klass.rb, line 79
def collect_repository_id(position = 4)
  response.path.split('/')[position]
end
collect_user_id(position = 1)
Alias for: collect_project_id
format_time?(time) click to toggle source

Formatting Time Helper

# File lib/labclient/klass.rb, line 127
def format_time?(time)
  time.respond_to?(:to_time)
end
group_name() click to toggle source

Category and Primary Key for docs

# File lib/labclient/klass.rb, line 84
def group_name
  self.class.instance_variable_get('@group_name') || klass.pluralize
end
help(help_filter = nil) click to toggle source

API Methods here have to be explicitly documented / custom helpers Assume no methods by default

# File lib/labclient/klass.rb, line 19
def help(help_filter = nil)
  docs = LabClient::Docs.docs.dig(group_name, 'Reference')
  unless docs
    puts 'No Available Help'
    return false
  end

  puts klass
  docs.each do |doc|
    next unless doc[:options]

    doc[:options].each do |opt|
      next if help_filter && !(opt[:name] + opt[:text]).include?(help_filter.to_s)

      puts "  #{opt[:name]}"
      puts "    #{opt[:text]}\n"
    end
  end

  # Ignore Output
  nil
end
klass() click to toggle source

Helper to get docs

# File lib/labclient/klass.rb, line 94
def klass
  self.class.name.split('::', 2).last.split(/(?=[A-Z])/).join(' ')
end
quiet?() click to toggle source

Quiet Reader Helper

# File lib/labclient/klass.rb, line 104
def quiet?
  client.quiet?
end
success?() click to toggle source

Forward response success

# File lib/labclient/klass.rb, line 122
def success?
  @response.success?
end
to_json(*_args) click to toggle source

Prevent stack level errors, but turning into has first

# File lib/labclient/klass.rb, line 89
def to_json(*_args)
  to_h.to_json
end
update_self(obj) click to toggle source
# File lib/labclient/klass.rb, line 98
def update_self(obj)
  @table = obj.table
  self
end
valid_group_project_levels() click to toggle source
# File lib/labclient/klass.rb, line 58
def valid_group_project_levels
  %i[guest reporter developer maintainer owner]
end
verbose() click to toggle source

TODO: Awesome Print / Amazing Print Conflicts?

# File lib/labclient/klass.rb, line 13
def verbose
  ap @table, ruby19_syntax: true
end