lib/pulse_meter/mixins/dumper.rb
# Serializes object and saves it to Redis
# @param safe [Boolean] forbids dump if sensor has already been dumped
# @raise [DumpConflictError] if object class conflicts with stored object class
# @raise [DumpError] if dumping fails for any reason
Serializes object and saves it to Redis
Serializes object and saves it to Redis
def dump!(safe = true)
          ensure_storability!
          serialized_obj = to_yaml
          if safe
            unless redis.hsetnx(DUMP_REDIS_KEY, name, serialized_obj)
              stored = self.class.restore(name)
              unless stored.class == self.class
                raise DumpConflictError, "Attempt to create sensor #{name} of class #{self.class} but it already has class #{stored.class}"
              end
            end
          else
            redis.hset(DUMP_REDIS_KEY, name, serialized_obj)
          end
        rescue DumpError, RestoreError => exc
          raise exc
        rescue StandardError => exc
          raise DumpError, "object cannot be dumped: #{exc}"
        end
def dump! ( safe = true ) ensure_storability! serialized_obj = to_yaml if safe unless redis . hsetnx ( DUMP_REDIS_KEY , name , serialized_obj ) stored = self . class . restore ( name ) unless stored . class == self . class raise DumpConflictError , "Attempt to create sensor #{name} of class #{self.class} but it already has class #{stored.class}" end end else redis . hset ( DUMP_REDIS_KEY , name , serialized_obj ) end rescue DumpError , RestoreError => exc raise exc rescue StandardError => exc raise DumpError , "object cannot be dumped: #{exc}" end
Serializes object and saves it to Redis
Serializes object and saves it to Redis
[DumpConflictError] if object class conflicts with stored object class
[ DumpConflictError ] if object class conflicts with stored object class
[DumpError] if dumping fails for any reason
[ DumpError ] if dumping fails for any reason
safe
forbids dump if sensor has already been dumped
forbids dump if sensor has already been dumped