Class: Badger::Badger
- Inherits:
-
Array
- Object
- Array
- Badger::Badger
- Defined in:
- lib/badger/badger.rb
Instance Attribute Summary collapse
-
#github_slug ⇒ Object
readonly
Returns the value of attribute github_slug.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Class Method Summary collapse
- .find_license(dir) ⇒ Object
- .gemfiles(dir) ⇒ Object
- .git_remote(dir) ⇒ Object
- .has_coveralls?(dir) ⇒ Boolean
- .has_gemfile?(dir) ⇒ Boolean
- .has_travis?(dir) ⇒ Boolean
- .is_repo?(dir) ⇒ Boolean
- .search_gemspec(dir) ⇒ Object
- .slug_extract(remote_url) ⇒ Object
- .spec_files(dir) ⇒ Object
Instance Method Summary collapse
- #add(service) ⇒ Object
- #bonus ⇒ Object
-
#initialize(url) ⇒ Badger
constructor
A new instance of Badger.
- #license(type) ⇒ Object
- #rubygem(name) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(url) ⇒ Badger
Returns a new instance of Badger.
5 6 7 |
# File 'lib/badger/badger.rb', line 5 def initialize url @url = url end |
Instance Attribute Details
#github_slug ⇒ Object (readonly)
Returns the value of attribute github_slug.
3 4 5 |
# File 'lib/badger/badger.rb', line 3 def github_slug @github_slug end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
3 4 5 |
# File 'lib/badger/badger.rb', line 3 def owner @owner end |
Class Method Details
.find_license(dir) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/badger/helpers.rb', line 53 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) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/badger/helpers.rb', line 46 def Badger.gemfiles dir targets = [] targets += (Dir.entries dir).select { |i| i =~ /Gemfile/ } targets += spec_files dir targets end |
.git_remote(dir) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/badger/helpers.rb', line 11 def Badger.git_remote dir remote = is_repo?(dir).remote.url if remote.nil? puts 'This repo does not appear to have a github remote' exit 2 end remote end |
.has_coveralls?(dir) ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'lib/badger/helpers.rb', line 33 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) ⇒ Boolean
29 30 31 |
# File 'lib/badger/helpers.rb', line 29 def Badger.has_gemfile? dir gemfiles(dir).any? end |
.has_travis?(dir) ⇒ Boolean
25 26 27 |
# File 'lib/badger/helpers.rb', line 25 def Badger.has_travis? dir ((Dir.entries dir).select { |i| '.travis.yml' == i }).any? end |
.is_repo?(dir) ⇒ Boolean
2 3 4 5 6 7 8 9 |
# 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 |
.search_gemspec(dir) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/badger/helpers.rb', line 68 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('spec.', '') l = eval (gs.grep /licenses?/)[0].sub('spec.', '') params[:licenses] = l.class.name == 'Array' ? l : [l] end params || nil end |
.slug_extract(remote_url) ⇒ Object
21 22 23 |
# File 'lib/badger/helpers.rb', line 21 def Badger.slug_extract remote_url remote_url.match(/.*github.com[\/:](.*)/)[1].gsub(/.git$/, '') end |
.spec_files(dir) ⇒ Object
42 43 44 |
# File 'lib/badger/helpers.rb', line 42 def Badger.spec_files dir (Dir.entries dir).select { |i| i =~ /gemspec/ } end |
Instance Method Details
#add(service) ⇒ Object
17 18 19 20 |
# File 'lib/badger/badger.rb', line 17 def add service self << Service.badge(service, github_slug) self.delete nil end |
#bonus ⇒ Object
31 32 33 34 |
# File 'lib/badger/badger.rb', line 31 def bonus self.uniq! self << Bonus.badge(self) end |
#license(type) ⇒ Object
22 23 24 25 |
# File 'lib/badger/badger.rb', line 22 def license type self << License.badge(type, owner) self.delete nil end |
#rubygem(name) ⇒ Object
27 28 29 |
# File 'lib/badger/badger.rb', line 27 def rubygem name self << Rubygem.badge(name) end |
#to_s ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/badger/badger.rb', line 36 def to_s self.uniq! s = '' self.each do |badge| s << badge s << "\n" end s end |