class SeoApp::FileStorage

Base storage interface

Attributes

reports_path[RW]

Public Class Methods

new() click to toggle source
# File lib/seo_app/storages/file_storage.rb, line 8
def initialize
  _path = SeoApp.configuration.reports_folder || ''
  # BUG! some wild problem with normal SeoApp.root_path.join(_path)
  @reports_path = File.join(SeoApp.root_path, _path)
end

Public Instance Methods

all_reports() click to toggle source
# File lib/seo_app/storages/file_storage.rb, line 14
def all_reports
  _reports = []

  Dir.foreach(@reports_path) do |file|
    next unless File.extname(file) == '.html'
    parts = file.gsub('.html', '').split('__')
    _reports << { site_url: parts[0],
                  date: parts[1].tr('_', ' '),
                  key: file
                }
  end
  _reports
end
report(_key) click to toggle source
# File lib/seo_app/storages/file_storage.rb, line 28
def report(_key)
  return nil unless File.exist?(@reports_path.join(_key))
  File.open(@reports_path.join(_key), 'r')
end
save_report(_data, _name) click to toggle source
# File lib/seo_app/storages/file_storage.rb, line 33
def save_report(_data, _name)
  puts @reports_path
  File.open(@reports_path.join(_name), 'w') do |f|
    f.write(_data)
  end
end