openSUSE/open-build-service

View on GitHub
src/api/app/models/owner.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
require 'api_error'

class Owner
  def self.attribute_names
    %i[rootproject project package filter users groups]
  end

  include ActiveModel::Model
  attr_accessor(*attribute_names)

  def user_or_group?
    users.present? || groups.present?
  end

  def to_hash
    # The same implemented as one-liner, but code climate doesn't like
    # Hash[*(Owner.attribute_names.map {|a| [a, send(a)] }.select {|a| !a.last.nil? }.flatten(1))]
    hash = {}
    Owner.attribute_names.map do |a|
      unless (value = send(a)).nil?
        hash[a] = value
      end
    end
    hash
  end
end