Class: Requestkit::Storage
- Inherits:
-
Object
- Object
- Requestkit::Storage
- Defined in:
- lib/requestkit/storage.rb
Instance Method Summary collapse
- #all ⇒ Object
- #by_namespace(namespace) ⇒ Object
- #clear ⇒ Object
-
#initialize(config) ⇒ Storage
constructor
A new instance of Storage.
- #namespaces ⇒ Object
- #store(namespace:, method:, path:, request:, timestamp:, direction: "inbound", response: nil, status: nil, parent_id: nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Storage
Returns a new instance of Storage.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/requestkit/storage.rb', line 8 def initialize(config) database_path = (config.storage == "file") ? config.database_path : ":memory:" if config.storage == "file" FileUtils.mkdir_p(File.dirname(config.database_path)) end @db = SQLite3::Database.new(database_path) @db.results_as_hash = true setup! end |
Instance Method Details
#all ⇒ Object
28 |
# File 'lib/requestkit/storage.rb', line 28 def all = @db.execute("SELECT * FROM requests ORDER BY id DESC") |
#by_namespace(namespace) ⇒ Object
32 |
# File 'lib/requestkit/storage.rb', line 32 def by_namespace(namespace) = @db.execute("SELECT * FROM requests WHERE namespace = ? ORDER BY id DESC", [namespace]) |
#clear ⇒ Object
34 |
# File 'lib/requestkit/storage.rb', line 34 def clear = @db.execute("DELETE FROM requests") |
#namespaces ⇒ Object
30 |
# File 'lib/requestkit/storage.rb', line 30 def namespaces = @db.execute("SELECT DISTINCT namespace FROM requests ORDER BY namespace").map { |row| row["namespace"] } |
#store(namespace:, method:, path:, request:, timestamp:, direction: "inbound", response: nil, status: nil, parent_id: nil) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/requestkit/storage.rb', line 21 def store(namespace:, method:, path:, request:, timestamp:, direction: "inbound", response: nil, status: nil, parent_id: nil) @db.execute( "INSERT INTO requests (namespace, direction, method, path, request, response, status, parent_id, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", [namespace, direction, method, path, request, response, status, parent_id, ] ) end |