Class: Gitloggl::Toggle::Cli

Inherits:
Object
  • Object
show all
Includes:
Hooks, Hooks::InstanceHooks
Defined in:
lib/gitloggl/toggle/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ Cli

Returns a new instance of Cli.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
# File 'lib/gitloggl/toggle/cli.rb', line 12

def initialize(params = {})
  params.each { |k, v| public_send("#{k}=", v) }
  yield(self) if block_given?
end

Instance Attribute Details

#date_fromObject

Returns the value of attribute date_from.



10
11
12
# File 'lib/gitloggl/toggle/cli.rb', line 10

def date_from
  @date_from
end

#date_toObject

Returns the value of attribute date_to.



10
11
12
# File 'lib/gitloggl/toggle/cli.rb', line 10

def date_to
  @date_to
end

#tokenObject

Returns the value of attribute token.



10
11
12
# File 'lib/gitloggl/toggle/cli.rb', line 10

def token
  @token
end

#verboseObject

Returns the value of attribute verbose.



10
11
12
# File 'lib/gitloggl/toggle/cli.rb', line 10

def verbose
  @verbose
end

#workspace_idObject

Returns the value of attribute workspace_id.



10
11
12
# File 'lib/gitloggl/toggle/cli.rb', line 10

def workspace_id
  @workspace_id
end

Instance Method Details

#run(page: 1) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gitloggl/toggle/cli.rb', line 17

def run(page: 1)
  body = request(page)

  total_count = body.fetch('total_count')
  per_page = body.fetch('per_page')
  total_pages = total_count.fdiv(per_page).ceil

  result = OpenStruct.new(
    total_count: total_count,
    per_page: per_page,
    total_pages: total_pages,
    page: page,
    body: body
  )

  run_hook(:on_first_page, result) if page == 1
  run_hook(:on_each_page, result)

  run(page: page.next) if body['data'].length >= per_page
end