Class: DaimonSkycrawlers::Storage::RDB

Inherits:
Base
  • Object
show all
Defined in:
lib/daimon_skycrawlers/storage/rdb.rb

Overview

Storage for RDBMS

Defined Under Namespace

Classes: Base, Page

Instance Method Summary collapse

Methods inherited from Base

#read

Methods included from LoggerMixin

included

Constructor Details

#initialize(config_path = "config/database.yml") ⇒ RDB



10
11
12
13
14
# File 'lib/daimon_skycrawlers/storage/rdb.rb', line 10

def initialize(config_path = "config/database.yml")
  super()
  Base.configurations = YAML.load(ERB.new(::File.read(config_path)).result)
  Base.establish_connection(DaimonSkycrawlers.env.to_sym)
end

Instance Method Details

#find(url) ⇒ Object

Fetch page identified by url



36
37
38
# File 'lib/daimon_skycrawlers/storage/rdb.rb', line 36

def find(url)
  Page.where(url: url).order(updated_at: :desc).limit(1).first
end

#save(url, headers, body) ⇒ Object

Save



23
24
25
26
27
28
29
# File 'lib/daimon_skycrawlers/storage/rdb.rb', line 23

def save(url, headers, body)
  Page.create(url: url,
              headers: JSON.generate(headers),
              body: body,
              last_modified_at: headers["last-modified"],
              etag: headers["etag"])
end