Class: JewelryPortfolio::ReposIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/jewelry_portfolio/repos_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, custom_work_directory = nil) ⇒ ReposIndex

Returns a new instance of ReposIndex.



11
12
13
# File 'lib/jewelry_portfolio/repos_index.rb', line 11

def initialize(, custom_work_directory = nil)
  @account, @custom_work_directory = , custom_work_directory
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



9
10
11
# File 'lib/jewelry_portfolio/repos_index.rb', line 9

def 
  @account
end

Instance Method Details

#add(repo) ⇒ Object



45
46
47
48
# File 'lib/jewelry_portfolio/repos_index.rb', line 45

def add(repo)
  @repos = Set.new([repo]).merge(@repos)
  update_repos_file!
end

#commit!(message) ⇒ Object



50
51
52
53
# File 'lib/jewelry_portfolio/repos_index.rb', line 50

def commit!(message)
  pages_repo.add
  reraise_with_path { pages_repo.commit(message) }
end

#pages_repoObject



27
28
29
30
# File 'lib/jewelry_portfolio/repos_index.rb', line 27

def pages_repo
  load_pages_repo!
  @pages_repo
end

#pathObject



19
20
21
# File 'lib/jewelry_portfolio/repos_index.rb', line 19

def path
  @path ||= @custom_work_directory || File.join(Dir.tmpdir, repo_name)
end

#push!Object



55
56
57
58
# File 'lib/jewelry_portfolio/repos_index.rb', line 55

def push!
  puts "Pushing branch `master' to remote `#{url}'"
  reraise_with_path { pages_repo.push('origin', 'master') }
end

#repo_nameObject



23
24
25
# File 'lib/jewelry_portfolio/repos_index.rb', line 23

def repo_name
  @repo_name ||= "#{@account.downcase}.github.com.git"
end

#reposObject



36
37
38
39
40
41
42
43
# File 'lib/jewelry_portfolio/repos_index.rb', line 36

def repos
  unless @repos
    load_pages_repo!
    data = File.read(repos_file) if File.exist?(repos_file)
    @repos = data.nil? || data.empty? ? Set.new : YAML.load(data).to_set
  end
  @repos
end

#repos_fileObject



32
33
34
# File 'lib/jewelry_portfolio/repos_index.rb', line 32

def repos_file
  File.join(path, 'repos.yml')
end

#to_yamlObject



60
61
62
# File 'lib/jewelry_portfolio/repos_index.rb', line 60

def to_yaml
  repos.to_a.to_yaml
end

#urlObject



15
16
17
# File 'lib/jewelry_portfolio/repos_index.rb', line 15

def url
  "[email protected]:#{@account}/#{repo_name}"
end