Module: SSD::Internals::InstanceMethods

Defined in:
lib/ssd/instance_methods.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ssdObject

Returns the value of attribute ssd.



9
10
11
# File 'lib/ssd/instance_methods.rb', line 9

def ssd
  @ssd
end

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/ssd/instance_methods.rb', line 5

def self.included(base)
  @@ssd_name     = base.new.class.to_s.downcase
end

Instance Method Details

#[]=Object Also known as: append!, save!, store!



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ssd/instance_methods.rb', line 28

def []= 
  @@ssd_path     = ".ssd/#{@@ssd_name}/#{@ssd}.ssd" 
  @@ssd_db     = PStore.new @@ssd_path, true
  begin  
    if !@ssd.nil? then 
      @@ssd_db.transaction do
 #todo should be somthing like??? timestamp instead of ssd as a key?? and use .last while reading
 @@ssd_db[Time.now.utc.to_s + "_" + Random.new_seed.to_s ] = self 
      end
    else
      raise 'ssd key can not be nil. see more (documentation url)'  
    end
  end  
end

#transactionObject



21
22
23
24
25
26
# File 'lib/ssd/instance_methods.rb', line 21

def transaction
  @@ssd_db.transaction do
    yield @@ssd_db
    @@ssd_db.commit
  end
end