Class: DatabaseRecorder::Storage::File
  
  
  
  
  
    - Inherits:
 
    - 
      Base
      
        
          - Object
 
          
            - Base
 
          
            - DatabaseRecorder::Storage::File
 
          
        
        show all
      
     
  
  
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/database_recorder/storage/file.rb
 
  
  
 
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from Base
  #initialize
  
    Instance Method Details
    
      
  
  
    #load  ⇒ Object 
  
  
  
  
    
      
9
10
11
12
13
14
15
16
17
18
19
20 
     | 
    
      # File 'lib/database_recorder/storage/file.rb', line 9
def load
  stored_data = ::File.exist?(storage_path) ? ::File.read(storage_path) : false
  if stored_data
    parsed_data = YAML.load(stored_data)     data = Core.symbolize_recursive(parsed_data)
    @recording.cache = data[:queries] || []
    @recording.entities = data[:entities]
    true
  else
    false
  end
end
     | 
  
 
    
      
  
  
    #save  ⇒ Object 
  
  
  
  
    
      
22
23
24
25
26
27
28
29
30 
     | 
    
      # File 'lib/database_recorder/storage/file.rb', line 22
def save
  data = {}
  data[:metadata] = @recording.metadata unless @recording.metadata.empty?
  data[:queries] = @recording.queries if @recording.queries.any?
  data[:entities] = @recording.entities if @recording.entities.any?
  serialized_data = ::YAML.dump(Core.string_keys_recursive(data))
  ::File.write(storage_path, serialized_data)
  true
end
     | 
  
 
    
      
  
  
    #storage_path  ⇒ Object 
  
  
  
  
    
      
32
33
34
35
36
37
38
39 
     | 
    
      # File 'lib/database_recorder/storage/file.rb', line 32
def storage_path
  @storage_path ||= begin
    name = normalize_name(@name)
    path = @options[:recordings_path] || 'spec/dbr'
    ::FileUtils.mkdir_p(path)
    "#{path}/#{name}.yml"
  end
end
     |