Class: Filestorage::LocalRandom
- Defined in:
- lib/filestorage/local_random.rb
Constant Summary collapse
- DEFAULT_LETTERS =
"abcdefghijklmnopqrstuvwxyz0123456789"
- DEFAULT_LENGTH =
8
Instance Method Summary collapse
-
#initialize(base_dir, length = DEFAULT_LENGTH) ⇒ LocalRandom
constructor
A new instance of LocalRandom.
- #store(file) ⇒ Object
Methods inherited from Local
#delete, #exist?, #files, #get
Constructor Details
#initialize(base_dir, length = DEFAULT_LENGTH) ⇒ LocalRandom
Returns a new instance of LocalRandom.
16 17 18 19 20 21 |
# File 'lib/filestorage/local_random.rb', line 16 def initialize(base_dir, length = DEFAULT_LENGTH) @base_dir = Pathname.new(base_dir) @filename_length = length @letter_pool = DEFAULT_LETTERS @pool_size = @letter_pool.size end |
Instance Method Details
#store(file) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/filestorage/local_random.rb', line 23 def store(file) begin filename = gen_random + File.extname(file) path = [filename[0, 2].upcase, filename[2, 2].upcase, filename].join("/") super(file, path) rescue AlreadyExist retry end path end |