Class: ChangeAgent::Client

Inherits:
Object
  • Object
show all
Includes:
Sync
Defined in:
lib/change_agent/client.rb

Constant Summary

Constants included from Sync

Sync::DEFAULT_LOCAL_REF, Sync::DEFAULT_REMOTE, Sync::DEFAULT_REMOTE_BRANCH

Instance Attribute Summary collapse

Attributes included from Sync

#credentials

Instance Method Summary collapse

Methods included from Sync

#add_remote, #fetch, #has_remotes?, #merge, #pull, #push, #remotes, #sync

Constructor Details

#initialize(directory = nil, remote = nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/change_agent/client.rb', line 8

def initialize(directory = nil, remote = nil)
  @directory = File.expand_path(directory || Dir.pwd)
  @remote = remote
end

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



6
7
8
# File 'lib/change_agent/client.rb', line 6

def directory
  @directory
end

Instance Method Details

#delete(key) ⇒ Object



38
39
40
# File 'lib/change_agent/client.rb', line 38

def delete(key)
  Document.new(key, self).delete
end

#get(key) ⇒ Object



30
31
32
# File 'lib/change_agent/client.rb', line 30

def get(key)
  get_document(key).contents
end

#get_document(key) ⇒ Object



34
35
36
# File 'lib/change_agent/client.rb', line 34

def get_document(key)
  Document.new(key, self)
end

#inspectObject



42
43
44
# File 'lib/change_agent/client.rb', line 42

def inspect
  "#<ChangeAgent::Client repo=\"#{directory}\">"
end

#repoObject



13
14
15
16
17
18
19
# File 'lib/change_agent/client.rb', line 13

def repo
  @repo ||= if @remote.nil?
              Rugged::Repository.init_at directory
            else
              Rugged::Repository.clone_at @remote, directory, { credentials: credentials }
            end
end

#set(key, value) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/change_agent/client.rb', line 21

def set(key, value)
  document = Document.new(key, self)
  document.contents = value
  return unless document.changed?

  document.save
  document
end