Class: CodeLines::GitHub

Inherits:
Adapter show all
Defined in:
lib/codelines/adapters/github.rb

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ GitHub

Returns a new instance of GitHub.



16
17
18
19
20
# File 'lib/codelines/adapters/github.rb', line 16

def initialize(profile)
  @profile      = profile
  @github       = Github.new
  @repositories = {}
end

Instance Method Details

#authenticate(username, password) ⇒ Object Also known as: login



22
23
24
# File 'lib/codelines/adapters/github.rb', line 22

def authenticate(username, password)
  @github = Github.new basic_auth: "#{username}:#{password}"
end

#count(options = {}, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/codelines/adapters/github.rb', line 27

def count(options = {}, &block)
  repos           = options[:repository     ] || []
  ignore_comments = options[:ignore_comments] || false
  reload          = options[:reload]          || false

  lines = 0
  repos.each { |repo|
    name                = repo[:name]
    @repositories[name] = fetch(repo) if reload || !@repositories.include?(name)

    @repositories[name].each { |github|
      next if repo[:ignore].is_a?(Array) && repo[:ignore].include?(github.name)

      source = Base64.decode64 github.content
      source.gsub!(/\r\n?/m, "\n")
      source.gsub!(/\/\*![^*]*\*+(?:[^*\/][^*]*\*+)*\//m, '') if ignore_comments

      source.each_line { |line|
        lines += 1 if ignore_comments == false || !comment?(line)
      }

      yield github if block_given?
    }
  }
  lines
end