Class: DaimonSkycrawlers::Storage::RDB
- Defined in:
- lib/daimon_skycrawlers/storage/rdb.rb
Overview
Storage for RDBMS
Defined Under Namespace
Instance Method Summary collapse
-
#find(url) ⇒ Object
Fetch page identified by url.
-
#initialize(config_path = "config/database.yml") ⇒ RDB
constructor
A new instance of RDB.
-
#save(url, headers, body) ⇒ Object
Save.
Methods inherited from Base
Methods included from LoggerMixin
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
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
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 |