Class: Djin::RemoteConfigRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/djin/repositories/remote_config_repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_configs, base_path: Pathname.new('~/.djin/remote'), stderr: Djin.stderr) ⇒ RemoteConfigRepository

Returns a new instance of RemoteConfigRepository.



7
8
9
10
11
# File 'lib/djin/repositories/remote_config_repository.rb', line 7

def initialize(remote_configs, base_path: Pathname.new('~/.djin/remote'), stderr: Djin.stderr)
  @remote_configs = remote_configs
  @base_path = base_path
  @stderr = stderr
end

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



5
6
7
# File 'lib/djin/repositories/remote_config_repository.rb', line 5

def base_path
  @base_path
end

Instance Method Details

#add(remote_config) ⇒ Object



13
14
15
# File 'lib/djin/repositories/remote_config_repository.rb', line 13

def add(remote_config)
  remote_configs << remote_config
end

#clearObject



40
41
42
43
44
45
46
47
# File 'lib/djin/repositories/remote_config_repository.rb', line 40

def clear
  remote_configs_by_folders.each do |rc|
    git_folder = base_path.join(rc.folder_name)

    stderr.puts "Removing #{rc.folder_name} repository..."
    `rm -rf #{git_folder}`
  end
end

#clear_allObject



49
50
51
# File 'lib/djin/repositories/remote_config_repository.rb', line 49

def clear_all
  remove_remote_folder
end

#fetch_allObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/djin/repositories/remote_config_repository.rb', line 25

def fetch_all
  remote_configs_by_folders.each do |rc|
    git_folder = base_path.join(rc.folder_name).expand_path

    # TODO: Extract STDEER Output, maybe publishing events and subscribing a observer for the logs.
    stderr.puts "Remote Path: #{base_path.expand_path}"

    git_repo = rc.missing? ? clone_repo(git_folder, rc) : fetch_repo(git_folder, rc)

    stderr.puts "Checking out to '#{rc.version}'"
    git_repo.checkout(rc.version)
    git_repo.pull('origin', rc.version)
  end
end

#find(**filters) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/djin/repositories/remote_config_repository.rb', line 17

def find(**filters)
  remote_configs.select do |remote_config|
    filters.reduce(true) do |memo, (filter_key, filter_value)|
      memo && remote_config.public_send(filter_key) == filter_value
    end
  end
end

#remote_configsObject



53
54
55
# File 'lib/djin/repositories/remote_config_repository.rb', line 53

def remote_configs
  @remote_configs ||= []
end