Class: ChangeAgent::Document
- Inherits:
-
Object
- Object
- ChangeAgent::Document
- Defined in:
- lib/change_agent/document.rb
Instance Attribute Summary collapse
- #contents ⇒ Object
-
#path ⇒ Object
(also: #key)
Returns the value of attribute path.
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #delete(file = path) ⇒ Object
-
#initialize(path, client_or_directory = nil) ⇒ Document
constructor
A new instance of Document.
- #inspect ⇒ Object
- #repo ⇒ Object
- #save ⇒ Object (also: #write)
Constructor Details
#initialize(path, client_or_directory = nil) ⇒ Document
Returns a new instance of Document.
8 9 10 11 12 13 14 15 |
# File 'lib/change_agent/document.rb', line 8 def initialize(path, client_or_directory=nil) @path = path if client_or_directory.class == ChangeAgent::Client @client = client_or_directory else @client = ChangeAgent::Client.new(client_or_directory) end end |
Instance Attribute Details
#contents ⇒ Object
21 22 23 |
# File 'lib/change_agent/document.rb', line 21 def contents @contents ||= blob_contents end |
#path ⇒ Object Also known as: key
Returns the value of attribute path.
5 6 7 |
# File 'lib/change_agent/document.rb', line 5 def path @path end |
Instance Method Details
#changed? ⇒ Boolean
25 26 27 |
# File 'lib/change_agent/document.rb', line 25 def changed? contents != blob_contents end |
#delete(file = path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/change_agent/document.rb', line 41 def delete(file=path) repo.index.remove(file) Rugged::Commit.create repo, message: "Removing #{path}", parents: [repo.head.target], tree: repo.index.write_tree(repo), update_ref: 'HEAD' rescue Rugged::IndexError false end |
#inspect ⇒ Object
53 54 55 |
# File 'lib/change_agent/document.rb', line 53 def inspect "#<ChangeAgent::Document path=\"#{path}\">" end |
#repo ⇒ Object
17 18 19 |
# File 'lib/change_agent/document.rb', line 17 def repo @client.repo end |
#save ⇒ Object Also known as: write
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/change_agent/document.rb', line 29 def save oid = repo.write contents, :blob repo.index.add(path: path, oid: oid, mode: 0100644) Rugged::Commit.create repo, message: "Updating #{path}", parents: repo.empty? ? [] : [ repo.head.target ], tree: repo.index.write_tree(repo), update_ref: 'HEAD' end |