class Badger::Badger
Attributes
github_slug[R]
owner[R]
Public Class Methods
find_license(dir)
click to toggle source
# File lib/badger/helpers.rb, line 64 def Badger.find_license dir license_file = (Dir.entries dir).select { |i| i =~ /LICENSE/ }[0] if license_file words = File.open(File.join(dir, license_file), 'r').read Config.instance.licenses.each_pair do |k, v| if words =~ /#{v['regex']}/im return k end end end nil end
gemfiles(dir)
click to toggle source
# File lib/badger/helpers.rb, line 57 def Badger.gemfiles dir targets = [] targets += (Dir.entries dir).select { |i| i =~ /Gemfile/ } targets += spec_files dir targets end
git_remote(dir)
click to toggle source
# File lib/badger/helpers.rb, line 11 def Badger.git_remote dir begin remote = nil is_repo?(dir).remotes.each do |r| if r.url.match /github.com/ remote = r.url end end rescue NoMethodError puts 'This repo does not appear to have a github remote' exit 2 end if remote.nil? puts 'This repo does not appear to have a github remote' exit 2 end remote end
has_coveralls?(dir)
click to toggle source
# File lib/badger/helpers.rb, line 44 def Badger.has_coveralls? dir lines = [] gemfiles(dir).each do |gemfile| lines += File.readlines(File.join(dir, gemfile)) end lines.grep(/coveralls/).any? end
has_gemfile?(dir)
click to toggle source
# File lib/badger/helpers.rb, line 40 def Badger.has_gemfile? dir gemfiles(dir).any? end
has_travis?(dir)
click to toggle source
# File lib/badger/helpers.rb, line 36 def Badger.has_travis? dir ((Dir.entries dir).select { |i| '.travis.yml' == i }).any? end
is_repo?(dir)
click to toggle source
# File lib/badger/helpers.rb, line 2 def Badger.is_repo? dir begin Git.open(dir) rescue ArgumentError puts 'Run this from inside a git repo' exit 1 end end
new(url)
click to toggle source
# File lib/badger/badger.rb, line 5 def initialize url @url = url end
search_gemspec(dir)
click to toggle source
# File lib/badger/helpers.rb, line 79 def Badger.search_gemspec dir spec_file = spec_files(dir)[0] if spec_file params = {} gs = File.readlines(File.join(dir, spec_file)) params[:rubygem] = eval (gs.grep /\.name /)[0].sub(/^\s.*\./, '') lines = (gs.grep /licenses?/) if lines.any? l = eval (lines[0]).sub(/^\s.*\./, '') params[:licenses] = l.class.name == 'Array' ? l : [l] end end params || nil end
slug_extract(remote_url)
click to toggle source
# File lib/badger/helpers.rb, line 32 def Badger.slug_extract remote_url remote_url.match(/.*github.com[\/:](.*)/)[1].gsub(/.git$/, '') end
spec_files(dir)
click to toggle source
# File lib/badger/helpers.rb, line 53 def Badger.spec_files dir (Dir.entries dir).select { |i| i =~ /gemspec/ } end
Public Instance Methods
add(service)
click to toggle source
# File lib/badger/badger.rb, line 17 def add service self << Service.badge(service, github_slug) self.delete nil end
badge_type(type)
click to toggle source
# File lib/badger/badger.rb, line 40 def badge_type type Config.instance.config['badge_type'] = type end
bonus()
click to toggle source
# File lib/badger/badger.rb, line 35 def bonus self.uniq! self << Bonus.badge(self) end
dependencyci()
click to toggle source
# File lib/badger/badger.rb, line 31 def dependencyci self << DependencyCI.badge(github_slug) end
license(type)
click to toggle source
# File lib/badger/badger.rb, line 22 def license type self << License.badge(type, owner) self.delete nil end
rubygem(name)
click to toggle source
# File lib/badger/badger.rb, line 27 def rubygem name self << Rubygem.badge(name) end
style(style)
click to toggle source
# File lib/badger/badger.rb, line 44 def style style unless Config.instance.config['valid_styles'].include? style puts "Invalid style choice '#{style}'" exit 3 end Config.instance.config['badge_style'] = style end
to_s()
click to toggle source
# File lib/badger/badger.rb, line 53 def to_s self.uniq! s = '' self.each do |badge| s << badge s << "\n" end s end