Class: SocialSnippet::Repository::RepositoryInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/social_snippet/repository/repository_installer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_social_snippet) ⇒ RepositoryInstaller

Returns a new instance of RepositoryInstaller


10
11
12
13
# File 'lib/social_snippet/repository/repository_installer.rb', line 10

def initialize(new_social_snippet)
  @social_snippet = new_social_snippet
  init_data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data


8
9
10
# File 'lib/social_snippet/repository/repository_installer.rb', line 8

def data
  @data
end

#social_snippetObject (readonly)

Returns the value of attribute social_snippet


7
8
9
# File 'lib/social_snippet/repository/repository_installer.rb', line 7

def social_snippet
  @social_snippet
end

Instance Method Details

#add(repo_name, repo_ref) ⇒ Object


42
43
44
45
46
# File 'lib/social_snippet/repository/repository_installer.rb', line 42

def add(repo_name, repo_ref)
  data[repo_name] ||= Set.new
  data[repo_name].add repo_ref
  save
end

#copy_repository(repo, options = {}) ⇒ Object


63
64
65
66
# File 'lib/social_snippet/repository/repository_installer.rb', line 63

def copy_repository(repo, options = {})
  social_snippet.logger.debug "repository_installer: repo.path = #{repo.path}"
  ::FileUtils.cp_r repo.path, repo_path(repo.name)
end

#data_fileObject


19
20
21
# File 'lib/social_snippet/repository/repository_installer.rb', line 19

def data_file
  social_snippet.config.installed_repos_file
end

#each(&block) ⇒ Object


77
78
79
80
81
82
# File 'lib/social_snippet/repository/repository_installer.rb', line 77

def each(&block)
  data
    .select {|repo_name, repo_refs| not repo_refs.empty? }
    .keys
    .each {|repo_name| block.call repo_name }
end

#exists?(repo_name, repo_ref = nil) ⇒ Boolean

Returns:

  • (Boolean)

54
55
56
57
58
59
60
61
# File 'lib/social_snippet/repository/repository_installer.rb', line 54

def exists?(repo_name, repo_ref = nil)
  data[repo_name] ||= Set.new
  if repo_ref.nil?
    data[repo_name].empty? === false
  else
    data[repo_name].include? repo_ref
  end
end

#fetch(repo_name, options) ⇒ Object


68
69
70
71
# File 'lib/social_snippet/repository/repository_installer.rb', line 68

def fetch(repo_name, options)
  repo = ::SocialSnippet::Repository::RepositoryFactory.create(repo_path(repo_name), options)
  repo.update
end

#init_dataObject


23
24
25
26
27
# File 'lib/social_snippet/repository/repository_installer.rb', line 23

def init_data
  ::FileUtils.touch data_file
  load
  reset unless data
end

#loadObject


34
35
36
# File 'lib/social_snippet/repository/repository_installer.rb', line 34

def load
  @data = ::YAML.load_file(data_file)
end

#pathObject


15
16
17
# File 'lib/social_snippet/repository/repository_installer.rb', line 15

def path
  social_snippet.config.install_path
end

#remove(repo_name, repo_ref) ⇒ Object


48
49
50
51
52
# File 'lib/social_snippet/repository/repository_installer.rb', line 48

def remove(repo_name, repo_ref)
  data[repo_name] ||= Set.new
  data[repo_name].delete repo_ref
  save
end

#repo_path(name) ⇒ Object


73
74
75
# File 'lib/social_snippet/repository/repository_installer.rb', line 73

def repo_path(name)
  ::File.join(path, name)
end

#resetObject


29
30
31
32
# File 'lib/social_snippet/repository/repository_installer.rb', line 29

def reset
  @data = {}
  save
end

#saveObject


38
39
40
# File 'lib/social_snippet/repository/repository_installer.rb', line 38

def save
  ::File.write data_file, data.to_yaml
end