Class: ChangeAgent::Client
- Inherits:
-
Object
- Object
- ChangeAgent::Client
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.
7
8
9
10
|
# File 'lib/change_agent/client.rb', line 7
def initialize(directory=nil, remote=nil)
@directory = File.expand_path(directory || Dir.pwd)
@remote = remote
end
|
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
5
6
7
|
# File 'lib/change_agent/client.rb', line 5
def directory
@directory
end
|
Instance Method Details
#delete(key) ⇒ Object
36
37
38
|
# File 'lib/change_agent/client.rb', line 36
def delete(key)
Document.new(key, self).delete
end
|
#get(key) ⇒ Object
28
29
30
|
# File 'lib/change_agent/client.rb', line 28
def get(key)
get_document(key).contents
end
|
#get_document(key) ⇒ Object
32
33
34
|
# File 'lib/change_agent/client.rb', line 32
def get_document(key)
Document.new(key, self)
end
|
#inspect ⇒ Object
40
41
42
|
# File 'lib/change_agent/client.rb', line 40
def inspect
"#<ChangeAgent::Client repo=\"#{directory}\">"
end
|
#repo ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/change_agent/client.rb', line 12
def repo
if @remote.nil?
@repo ||= Rugged::Repository.init_at directory
else
@repo ||= Rugged::Repository.clone_at @remote, directory, {:credentials => credentials}
end
end
|
#set(key, value) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/change_agent/client.rb', line 20
def set(key, value)
document = Document.new(key, self)
document.contents = value
return unless document.changed?
document.save
document
end
|