Class: LedgerRest::Git
- Inherits:
-
Object
- Object
- LedgerRest::Git
- Defined in:
- lib/ledger-rest/git.rb
Class Attribute Summary collapse
-
.branch ⇒ Object
readonly
Returns the value of attribute branch.
-
.read_pull_block_time ⇒ Object
readonly
Returns the value of attribute read_pull_block_time.
-
.remote ⇒ Object
readonly
Returns the value of attribute remote.
-
.repository ⇒ Object
readonly
Returns the value of attribute repository.
Class Method Summary collapse
- .blocked_read_pull? ⇒ Boolean
- .configure(options) ⇒ Object
- .invoke(hook) ⇒ Object
-
.pull ⇒ Object
Execute the pull command.
- .pull_before_read? ⇒ Boolean
- .pull_before_write? ⇒ Boolean
-
.push ⇒ Object
Execute the push command after commiting all.
- .push_after_write? ⇒ Boolean
Class Attribute Details
.branch ⇒ Object (readonly)
Returns the value of attribute branch.
8 9 10 |
# File 'lib/ledger-rest/git.rb', line 8 def branch @branch end |
.read_pull_block_time ⇒ Object (readonly)
Returns the value of attribute read_pull_block_time.
8 9 10 |
# File 'lib/ledger-rest/git.rb', line 8 def read_pull_block_time @read_pull_block_time end |
.remote ⇒ Object (readonly)
Returns the value of attribute remote.
8 9 10 |
# File 'lib/ledger-rest/git.rb', line 8 def remote @remote end |
.repository ⇒ Object (readonly)
Returns the value of attribute repository.
8 9 10 |
# File 'lib/ledger-rest/git.rb', line 8 def repository @repository end |
Class Method Details
.blocked_read_pull? ⇒ Boolean
38 39 40 |
# File 'lib/ledger-rest/git.rb', line 38 def blocked_read_pull? (Time.new - @last_read_pull) > read_pull_block_time end |
.configure(options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ledger-rest/git.rb', line 10 def configure() @repository = [:git_repository] || File.dirname([:ledger_file] || 'main.ledger') @pull_before_read = [:git_pull_before_read] || false @pull_before_write = [:git_pull_before_write] || false @push_after_write = [:git_push_after_write] || false @remote = [:git_remote] || 'origin' @branch = [:git_branch] || 'master' @read_pull_block_time = [:git_read_pull_block_time] || 10*60 @last_read_pull = Time.new if pull_before_read? || pull_before_write? || push_after_write? @git_repo = ::Git.open(repository) FileUtils.touch([:ledger_append_file]) @git_repo.add([:ledger_append_file]) end end |
.invoke(hook) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ledger-rest/git.rb', line 27 def invoke(hook) case hook when :before_read pull if pull_before_read? && !blocked? when :before_write pull if pull_before_write? when :after_write push if push_after_write? end end |
.pull ⇒ Object
Execute the pull command.
55 56 57 58 59 60 |
# File 'lib/ledger-rest/git.rb', line 55 def pull @git_repo.pull(remote, branch) @last_read_pull = Time.new rescue Exception => e $stderr.puts "Git pull failed: #{e}" end |
.pull_before_read? ⇒ Boolean
42 43 44 |
# File 'lib/ledger-rest/git.rb', line 42 def pull_before_read? @pull_before_read end |
.pull_before_write? ⇒ Boolean
46 47 48 |
# File 'lib/ledger-rest/git.rb', line 46 def pull_before_write? @pull_before_write end |
.push ⇒ Object
Execute the push command after commiting all.
63 64 65 66 67 68 |
# File 'lib/ledger-rest/git.rb', line 63 def push @git_repo.commit_all('Add transaction via ledger-rest') @git_repo.push(remote, branch) rescue Exception => e $stderr.put "Git push failed: #{e}" end |
.push_after_write? ⇒ Boolean
50 51 52 |
# File 'lib/ledger-rest/git.rb', line 50 def push_after_write? @push_after_write end |