Module: Cached
- Defined in:
- lib/cached.rb
Class Method Summary collapse
Class Method Details
.exec(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cached.rb', line 39 def self.exec(*args) ttl = 3600 case args.first when /^--ttl=([0-9]+)$/ args.shift ttl = $1.to_i end key = Digest::SHA1.hexdigest(Dir.getwd + ":" + args.inspect) Entry.get(key) || begin value = run(*args) Entry.set(key, value, :ttl => ttl) value end end |
.run(*args) ⇒ Object
76 77 78 79 80 |
# File 'lib/cached.rb', line 76 def self.run(*args) command = args.join(" ") # command = shell_escape args `#{command}` end |
.shell_escape(*args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cached.rb', line 56 def self.shell_escape(*args) args.map do |str| if str.empty? "''" elsif %r{\A[0-9A-Za-z+,./:=@_-]+\z} =~ str str else result = '' str.scan(/('+)|[^']+/) { if $1 result << %q{\'} * $1.length else result << "'#{$&}'" end } result end end.join(" ") end |