Class: Checklister::Github::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/checklister/github/project.rb

Constant Summary collapse

DEFAULT_OPTIONS =

Default options that we want to pass when querying the github project index

{ sort: "full_name", direction: "asc" }

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Project

Initialize a github project instance

Examples:

Get a project's data

project = Checklister::Project.new(gitlab_client).get(1)

Parameters:

  • client (Object)

    an instance of Checklister::Client



38
39
40
# File 'lib/checklister/github/project.rb', line 38

def initialize(client)
  @client = client
end

Instance Method Details

#all(options = {}) ⇒ Array

Get all github's projects

Parameters:

  • options (optional, Hash) (defaults to: {})

    query options

Returns:

  • (Array)

    and array of project's properties as Hash



52
53
54
55
56
# File 'lib/checklister/github/project.rb', line 52

def all(options = {})
  query_options = DEFAULT_OPTIONS.merge options
  repositories = @client.repositories(query_options)
  repositories.map { |p| ProjectDecorator.new(p).to_hash }
end

#filtered_by_name(name, _options = {}) ⇒ Array

Get github's projects based on a search string (LIKE on project#name)

Parameters:

  • name (String)

    partial project's name

Returns:

  • (Array)

    and array of project's properties as Hash



61
62
63
# File 'lib/checklister/github/project.rb', line 61

def filtered_by_name(name, _options = {})
  all.select { |p| p[:name].downcase.include? name.downcase }
end

#get(project_id) ⇒ Hash

Query a particular project based on it's id

Parameters:

  • project_id (Integer)

    github project id

Returns:

  • (Hash)

    a project properties



45
46
47
# File 'lib/checklister/github/project.rb', line 45

def get(project_id)
  ProjectDecorator.new(@client.repository(project_id)).to_hash
end