Module: PulseMeter::Mixins::Dumper::ClassMethods

Defined in:
lib/pulse-meter/mixins/dumper.rb

Instance Method Summary collapse

Instance Method Details

#list_namesArray<String>

Lists all dumped objects’ names

Returns:

  • (Array<String>)

Raises:

  • (RestoreError)

    if list cannot be retrieved for any reason



60
61
62
63
64
# File 'lib/pulse-meter/mixins/dumper.rb', line 60

def list_names
  PulseMeter.redis.hkeys(DUMP_REDIS_KEY)
rescue
  raise RestoreError, "cannot get data from redis"
end

#list_objectsArray<Object>

Safely restores all dumped objects

Returns:

  • (Array<Object>)


68
69
70
71
72
73
74
75
76
77
# File 'lib/pulse-meter/mixins/dumper.rb', line 68

def list_objects
  objects = []
  list_names.each do |name|
    begin
      objects << restore(name)
    rescue
    end
  end
  objects
end

#restore(name) ⇒ Object

Restores object from Redis

Parameters:

  • name (String)

    object name

Returns:

  • (Object)

Raises:

  • (RestoreError)

    if object cannot be restored for any reason



50
51
52
53
54
55
# File 'lib/pulse-meter/mixins/dumper.rb', line 50

def restore(name)
  serialized_obj = PulseMeter.redis.hget(DUMP_REDIS_KEY, name)
  YAML::load(serialized_obj)
rescue
  raise RestoreError, "cannot restore #{name}"
end