Sha256: b2718160fafea8f21eedd9b328010876ff82dc8f5c543defd0d965b1d0bd961f

Contents?: true

Size: 1.34 KB

Versions: 13

Compression:

Stored size: 1.34 KB

Contents

module Datapimp::Sources
  class GithubRepository < Datapimp::Sources::Base
    attr_reader :options, :repository

    def initialize(repository, options)
      @repository = repository
      @options    = options.to_mash
    end

    def all
      %w(issues milestones commits releases).reduce({}) do |memo, slice|
        memo[slice] = send(slice)
        memo
      end
    end

    def to_s
      all
    end

    def issues
      issues = client.issues(repository, filter: "all")
      issues.map! do |issue|
        %w(comments events labels).each do |rel|
          issue[rel] = issue.rels[rel].get.data if relations.include?(rel)
        end
        issue
      end
      serve_output(issues)
    end

    def milestones
      milestones = client.milestones(repository)
      serve_output(milestones)
    end

    def releases
      releases = client.releases(repository)
      serve_output(releases)
    end

    def commits
      commits = client.commits(repository)
      serve_output(commits)
    end

    private

    def client
      @_client ||= Datapimp::Sync.github.api
    end

    def relations
      @_relations ||= Array(@options.relations)
    end

    def serve_output(output)
      if output.is_a?(Array)
        output.map! do |o|
          o.respond_to?(:to_attrs) ? o.send(:to_attrs) : o
        end
      end

      output
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
datapimp-1.2.11 lib/datapimp/sources/github_repository.rb
datapimp-1.2.10 lib/datapimp/sources/github_repository.rb
datapimp-1.2.9 lib/datapimp/sources/github_repository.rb
datapimp-1.2.8 lib/datapimp/sources/github_repository.rb
datapimp-1.2.7 lib/datapimp/sources/github_repository.rb
datapimp-1.2.6 lib/datapimp/sources/github_repository.rb
datapimp-1.2.5 lib/datapimp/sources/github_repository.rb
datapimp-1.2.4 lib/datapimp/sources/github_repository.rb
datapimp-1.2.3 lib/datapimp/sources/github_repository.rb
datapimp-1.2.2 lib/datapimp/sources/github_repository.rb
datapimp-1.2.1 lib/datapimp/sources/github_repository.rb
datapimp-1.2.0 lib/datapimp/sources/github_repository.rb
datapimp-1.1.1 lib/datapimp/sources/github_repository.rb