Class: Checklister::Gitlab::Project
- Inherits:
-
Object
- Object
- Checklister::Gitlab::Project
- Defined in:
- lib/checklister/gitlab/project.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options that we want to pass when querying the gitlab project index
{ order_by: "id", sort: "asc", per_page: "100" }
- MAX_PAGES =
5
Instance Method Summary collapse
-
#all(options = {}) ⇒ Array
Get all gitlab's projects.
-
#filtered_by_name(name) ⇒ Array
Get gitlab's projects based on a search string (LIKE on project#name).
-
#get(project_id) ⇒ Hash
Query a particular project based on it's id.
-
#initialize(client) ⇒ Project
constructor
Initialize a gitlab project instance.
Constructor Details
#initialize(client) ⇒ Project
Initialize a gitlab project instance
37 38 39 |
# File 'lib/checklister/gitlab/project.rb', line 37 def initialize(client) @client = client end |
Instance Method Details
#all(options = {}) ⇒ Array
Get all gitlab's projects
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/checklister/gitlab/project.rb', line 51 def all( = {}) = DEFAULT_OPTIONS.merge projects = [] page = 1 while page <= MAX_PAGES projects_per_page = @client.projects(.merge(page: page)) if projects_per_page == false || projects_per_page.empty? page = MAX_PAGES return projects else projects += projects_per_page.map { |p| ProjectDecorator.new(p).to_hash } page += 1 end end projects end |
#filtered_by_name(name) ⇒ Array
Get gitlab's projects based on a search string (LIKE on project#name)
71 72 73 |
# File 'lib/checklister/gitlab/project.rb', line 71 def filtered_by_name(name) all.select { |p| p[:name].downcase.include? name.downcase } end |
#get(project_id) ⇒ Hash
Query a particular project based on it's id
44 45 46 |
# File 'lib/checklister/gitlab/project.rb', line 44 def get(project_id) ProjectDecorator.new(@client.project(project_id)).to_hash end |