module SinderellaClone

Constants

VERSION

Public Class Methods

get(id) click to toggle source
# File lib/sinderella_clone.rb, line 22
def self.get(id)
  DataStore.instance.get(id)[:transformed]
end
midnight(id) click to toggle source
# File lib/sinderella_clone.rb, line 26
def self.midnight(id)
  reset_data_at id
end
transforms(data, till_midnight = 60) { |cloned_data| ... } click to toggle source
# File lib/sinderella_clone.rb, line 6
def self.transforms(data, till_midnight = 60)
  identifier  = Crimp.signature data
  cloned_data = deep_copy data
  transformed = yield cloned_data

  store(
    id:           identifier,
    original:     data,
    transformed:  transformed
  )

  check(identifier, till_midnight)

  identifier
end

Private Class Methods

check(id, seconds) click to toggle source
# File lib/sinderella_clone.rb, line 40
def self.check(id, seconds)
  Thread.new do
    sleep seconds
    reset_data_at id
  end
end
deep_copy(object) click to toggle source
# File lib/sinderella_clone.rb, line 36
def self.deep_copy(object)
  Marshal.load(Marshal.dump(object))
end
reset_data_at(id) click to toggle source
# File lib/sinderella_clone.rb, line 47
def self.reset_data_at(id)
  DataStore.instance.reset id
end
store(data) click to toggle source
# File lib/sinderella_clone.rb, line 32
def self.store(data)
  DataStore.instance.set data
end