Sha256: a8da2177149bda8baf36c111d56c5da52c482063ba2facc7dc421bfea216eee2

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'travis/client'

module Travis
  module Client
    class Account < Entity
      attributes :name, :login, :type, :repos_count, :subscribed, :education

      one :account
      many :accounts

      inspect_info :login
      id_field :login

      def self.cast_id(id)
        String(id)
      end

      def self.id?(object)
        object.is_a? String
      end

      def subscribed
        load_attribute('subscribed') { true } if member?
      end

      def education
        load_attribute('education') { false } if member?
      end

      def on_trial?
        !subscribed? and !education?
      end

      def repos_count
        load_attribute('repos_count') { repositories.count }
      end

      def repositories
        attributes['repositories'] ||= session.repos(owner_name: login)
      end

      def member?
        session.accounts.include? self
      end

      alias educational? education?

      private

      def load_attribute(name, &block)
        session.accounts if missing? name
        block ? attributes.fetch(name.to_s, &block) : attributes[name.to_s]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
travis-1.14.0 lib/travis/client/account.rb
travis-1.13.3 lib/travis/client/account.rb
travis-1.13.2 lib/travis/client/account.rb
travis-1.13.1 lib/travis/client/account.rb
travis-1.13.0 lib/travis/client/account.rb
travis-1.12.0 lib/travis/client/account.rb