mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-26 09:59:18 +01:00
implement memoization
Signed-off-by: Gwenhael Le Moine <gwenhael.le.moine@gmail.com>
This commit is contained in:
parent
657d4dd05e
commit
1f3c0d9e14
1 changed files with 146 additions and 135 deletions
|
@ -8,10 +8,21 @@ module Ledger
|
||||||
|
|
||||||
@binary = 'ledger'
|
@binary = 'ledger'
|
||||||
@file = ENV[ 'LEDGER_FILE' ]
|
@file = ENV[ 'LEDGER_FILE' ]
|
||||||
|
@last_mtime = Pathname.new(@file).mtime
|
||||||
|
|
||||||
|
@cache = Hash.new
|
||||||
|
|
||||||
def run( options, command = '', command_parameters = '' )
|
def run( options, command = '', command_parameters = '' )
|
||||||
STDERR.puts "#{@binary} -f #{@file} #{options} #{command} #{command_parameters}"
|
command = "#{@binary} -f #{@file} #{options} #{command} #{command_parameters}"
|
||||||
`#{@binary} -f #{@file} #{options} #{command} #{command_parameters}`
|
|
||||||
|
mtime = Pathname.new(@file).mtime
|
||||||
|
if @last_mtime < mtime || !@cache.has_key?( command )
|
||||||
|
@last_mtime = mtime
|
||||||
|
|
||||||
|
@cache[ command ] = `#{command}`
|
||||||
|
end
|
||||||
|
|
||||||
|
@cache[ command ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
|
|
Loading…
Reference in a new issue