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

Returns a new instance of 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_file(config_path)
  Base.establish_connection(DaimonSkycrawlers.env.to_sym)
end

Instance Method Details

#find(url) ⇒ Object

Fetch page identified by url

Parameters:

  • url (String)

    identity of the page



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

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

#save(url, headers, body) ⇒ Object

Save

Parameters:

  • url (String)

    identity of the page

  • header (Hash)

    of URL

  • body (String)


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