lib/isomorfeus/data/object_expander.rb in isomorfeus-data-2.1.1 vs lib/isomorfeus/data/object_expander.rb in isomorfeus-data-2.2.0

- old
+ new

@@ -7,26 +7,27 @@ end end attr_accessor :environment - def initialize(object_class_name, &block) + def initialize(class_name:, compress: false, &block) if block_given? res = block.call(self) self.environment = res unless self.environment else - @env_path = File.expand_path(File.join(Isomorfeus.data_object_envs_path, object_class_name.underscore)) + @env_path = File.expand_path(File.join(Isomorfeus.data_object_envs_path, class_name.underscore)) open_environment end @db = self.environment.database('objects', create: true) @index_db = self.environment.database('index', create: true, dupsort: true) + @compress = compress @use_class_cache = !Isomorfeus.development? ObjectSpace.define_finalizer(self, self.class.finalize(self)) end def create_object(sid_s, obj) - Isomorfeus::Hamster::Marshal.dump(@db, sid_s, obj, class_cache: @use_class_cache) + Isomorfeus::Hamster::Marshal.dump(@db, sid_s, obj, class_cache: @use_class_cache, compress: @compress) end def destroy_object(sid_s) @db.delete(sid_s) rescue nil true @@ -35,10 +36,10 @@ def load_object(sid_s) Isomorfeus::Hamster::Marshal.load(@db, sid_s, class_cache: @use_class_cache) end def save_object(sid_s, obj) - Isomorfeus::Hamster::Marshal.dump(@db, sid_s, obj, class_cache: @use_class_cache) + Isomorfeus::Hamster::Marshal.dump(@db, sid_s, obj, class_cache: @use_class_cache, compress: @compress) end def index_delete(key, val) @index_db.delete(key, val) rescue nil end