Sha256: e26a09ad370f05b0a5abefa1b968570b8c1d44d3d12aa9a9737056c6d54e93df

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

module GitHubRecordsArchiver
  class Team
    attr_reader :id
    attr_reader :organization

    include DataHelper

    KEYS = %i[name slug description privacy permission].freeze

    def initialize(org, id)
      org = Organization.new(org) if org.is_a? String
      @organization = org
      @id = id
    end

    def self.from_hash(org, hash)
      team = Team.new(org, hash[:id])
      team.instance_variable_set '@data', hash.to_h
      team
    end

    def data
      @data ||= GitHubRecordsArchiver.client.team id
    end

    def repositories
      @repositories ||= begin
        repos = GitHubRecordsArchiver.client.team_repositories id
        repos.map { |r| Repository.new(r) }
      end
    end

    def members
      @members ||= begin
        members = GitHubRecordsArchiver.client.team_members id
        members.map { |m| User.new(m) }
      end
    end

    def archive
      File.write(path, to_s)
    end

    def to_s
      meta_for_markdown.to_yaml
    end

    def as_json
      data.to_h.merge(repositories: repositories.map(&:name))
    end

    private

    def path
      File.expand_path "#{data[:slug]}.md", organization.teams_dir
    end

    def meta_for_markdown
      meta = {}
      KEYS.each { |key| meta[key.to_s] = data[key] }
      meta['repositories'] = repositories.map(&:name)
      meta['members'] = members.map(&:name)
      meta
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
github_records_archiver-0.3.1 lib/github_records_archiver/team.rb
github_records_archiver-0.2.0 lib/github_records_archiver/team.rb
github_records_archiver-0.1.0 lib/github_records_archiver/team.rb