Class: MultiRepo::Helpers::ReadmeBadges

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_repo/helpers/readme_badges.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, dry_run: false) ⇒ ReadmeBadges

Returns a new instance of ReadmeBadges.



8
9
10
11
12
13
14
15
16
17
# File 'lib/multi_repo/helpers/readme_badges.rb', line 8

def initialize(repo, dry_run: false, **)
  @repo    = repo
  @dry_run = dry_run

  if repo.dry_run != dry_run
    raise ArgumentError, "expected repo.dry_run (#{repo.dry_run}) to match dry_run (#{dry_run})"
  end

  reload
end

Instance Attribute Details

#badgesObject

Returns the value of attribute badges.



6
7
8
# File 'lib/multi_repo/helpers/readme_badges.rb', line 6

def badges
  @badges
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



5
6
7
# File 'lib/multi_repo/helpers/readme_badges.rb', line 5

def dry_run
  @dry_run
end

#repoObject (readonly)

Returns the value of attribute repo.



5
6
7
# File 'lib/multi_repo/helpers/readme_badges.rb', line 5

def repo
  @repo
end

Instance Method Details

#contentObject



34
35
36
37
# File 'lib/multi_repo/helpers/readme_badges.rb', line 34

def content
  return "" unless @file
  File.read(repo.path.join(@file))
end

#save!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/multi_repo/helpers/readme_badges.rb', line 19

def save!
  lines = content.lines

  apply_badges!(lines)
  save_contents!(lines.join)

  if dry_run
    reload(lines)
  else
    reload
  end

  true
end