Class: Stan::Compressor
- Inherits:
-
Object
- Object
- Stan::Compressor
- Defined in:
- lib/stan/compressor.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #compress ⇒ Object
-
#initialize(dir) ⇒ Compressor
constructor
A new instance of Compressor.
Constructor Details
#initialize(dir) ⇒ Compressor
Returns a new instance of Compressor.
6 7 8 9 |
# File 'lib/stan/compressor.rb', line 6 def initialize(dir) @tempdir = ENV.fetch('STAN_TEMP_DIR') @path = File.path(dir) end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
4 5 6 |
# File 'lib/stan/compressor.rb', line 4 def output @output end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/stan/compressor.rb', line 4 def path @path end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/stan/compressor.rb', line 4 def size @size end |
Instance Method Details
#compress ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/stan/compressor.rb', line 11 def compress FileUtils.mkdir_p(@tempdir) date = DateTime.now.strftime('%Y%m%d%H%M%S') @output = "#{@tempdir}/#{date}.tar.gz" Dir.chdir(path) do `tar -czf #{output} .` end @size = File.size(output) / 2**20 end |