Class: Moneta::Transforms::Spread

Inherits:
Moneta::Transform show all
Defined in:
lib/moneta/transforms/spread.rb

Overview

Transforms strings by inserting a “/” character after the first two characters, using File.join. This can be used with the Adapters::File adapter to spread files into subdirectories. The :HashFile option on Moneta.new uses this transform (in conjunction with MD5) - see README.

Examples:

transform = Moneta::Transforms::Spread.new
transform.encode('testing')  # => 'te/sting'
transform.encode('te/sting') # => 'te/sting'
transform.encode('tes/ting') # => 'te/s/ting'

Instance Method Summary collapse

Methods inherited from Moneta::Transform

#decodable?, #decode, delegate_to, #initialize, #method_missing, #respond_to_missing?

Constructor Details

This class inherits a constructor from Moneta::Transform

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Moneta::Transform

Instance Method Details

#encode(value) ⇒ String

Parameters:

  • value (String)

Returns:

  • (String)


17
18
19
# File 'lib/moneta/transforms/spread.rb', line 17

def encode(value)
  ::File.join(value[0..1], value [2..-1])
end