<commit_before>module Artifactory
  class Resource::User < Resource::Base
    class << self
      #
      #
      #
      def all(client)
        client.get('/api/security/users').map do |hash|
          from_url(client, hash['uri'])
        end
      end

      #
      #
      #
      def find(client, username)
        username = URI.escape(username)
        from_hash(client, client.get("/api/security/users/#{username}"))
      rescue Error::NotFound
        nil
      end

      #
      #
      #
      def from_url(client, url)
        from_hash(client, client.get(url))
      end

      #
      #
      #
      def from_hash(client, hash)
        new(client).tap do |instance|
          instance.admin      = hash['admin']
          instance.email      = hash['email']
          instance.last_login = Time.parse(hash['lastLoggedIn']) rescue nil
          instance.name       = hash['name']
          instance.realm      = hash['realm']
        end
      end
    end

    attribute :admin, false
    attribute :email
    attribute :last_login
    attribute :name, ->{ raise 'Name missing!' }
    attribute :password
    attribute :realm

    #
    # Create a new user object.
    #
    def initialize(client, attributes = {})
      attributes.each do |key, value|
        send("#{key}=", value)
      end
    end
  end
end<commit_msg>Update Uer resource to use new syntax<commit_after>module Artifactory
  class Resource::User < Resource::Base
    class << self
      #
      #
      #
      def all(options = {})
        client = extract_client!(options)
        client.get('/api/security/users').map do |hash|
          from_url(hash['uri'], client: client)
        end
      end

      #
      #
      #
      def find(options = {})
        client   = extract_client!(options)
        username = URI.escape(options[:username])
        response = client.get("/api/security/users/#{username}")
        from_hash(response, client: client)
      rescue Error::NotFound
        nil
      end

      #
      #
      #
      def from_url(url, options = {})
        client = extract_client!(options)
        from_hash(client.get(url), client: client)
      end

      #
      #
      #
      def from_hash(hash, options = {})
        client = extract_client!(options)

        new(client).tap do |instance|
          instance.admin      = hash['admin']
          instance.email      = hash['email']
          instance.last_login = Time.parse(hash['lastLoggedIn']) rescue nil
          instance.name       = hash['name']
          instance.realm      = hash['realm']
        end
      end
    end

    attribute :admin, false
    attribute :email
    attribute :last_login
    attribute :name, ->{ raise 'Name missing!' }
    attribute :password
    attribute :realm
  end
end
{'fraction_non_alphanumeric': 0.11487216420597768, 'fraction_numerical': 0.0, 'mean_word_length': 1.8145896656534954, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6324008', 'n_tokens_mistral': 794, 'n_tokens_neox': 790, 'n_words': 177}