repldb 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/repldb.rb +18 -12
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fca11f6e1224b47560db11dd0616a9957286bc652ef6bbc7920e759ed7ff144a
4
- data.tar.gz: 272ec9182a7e7d527e5dc321310a1b3a37f7b3510f748e39ee93af76167f5c41
3
+ metadata.gz: e725a97d9fad8f4ecc9a6d369f3928876061ba2df9cbf50c0ed40a57687592a9
4
+ data.tar.gz: bc2729273d394819373134cd044bbb836ee770020f01bccf8b0fa6b979cbefad
5
5
  SHA512:
6
- metadata.gz: c14295ccf368ae51c4ef37f4e56ded5dc15662f3f1c0e12967ada4ee61ab680c879eca0495649373e2824f460f346a2dddc1e67fc2978d1a5c0e3ef59ac86950
7
- data.tar.gz: 6b5f072be85b2020dfa7b563d9c507709e966ac1de2b5a78c3a7cde5cbe408350670159a71a3f09e5f3277cb5b6646b23b45691ce8535ec5fabc8c36041b60df
6
+ metadata.gz: 6a18e7feb555265bed09d7b26fced181fa42e43d2b113276dd2c42b1b0984d55fedbffef7317b0c9ba0cca28a0723eb43431a5a1901f3199f8cb43e867f0e562
7
+ data.tar.gz: 98be4f7bc5d88f78751c53bc33255be4b9c0956261977232492d3d999edb3ec2ecc88c0e2060131a7549bfa6f46903e65c49e482095ac44f0041b30a960b00e4
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ruby Repldb
2
2
  The ease of using repldb now meets the ease of developing in Ruby!
3
- You can learn more about repldb [here](https://docs.replit.com/misc/database)
3
+ You can learn more about repldb [here](https://docs.replit.com/misc/database).
4
4
 
5
5
  # Usage
6
6
  ```rb
data/lib/repldb.rb CHANGED
@@ -4,19 +4,23 @@ require 'json'
4
4
  require 'net/http'
5
5
 
6
6
  class Client
7
- # Change `url` to point to a different path.
7
+ # Change <tt>url</tt> to point to a different path.
8
+ # @param url [String, nil]
8
9
  def initialize(url = ENV['REPLIT_DB_URL'])
9
10
  @url = url
10
11
  end
11
12
 
12
- # Sets `key` to `val`.
13
+ # Sets <tt>key</tt> to <tt>val</tt>.
14
+ # @param key [String] the key to set.
15
+ # @param val [Any] the value.
13
16
  def set(key, val)
14
17
  post_url(@url.to_s, serialize(key) => JSON.generate(val))
15
18
  end
16
19
 
17
- # Gets `key`.
18
- #
19
- # If it doesn't exist, `default` will be used.
20
+ # Gets <tt>key</tt>.
21
+ # If it doesn't exist, <tt>default<tt> will be used.
22
+ # @param key [String] the key to get
23
+ # @param default [Any] the default value if the key doesn't exist.
20
24
  def get(key, default = nil)
21
25
  val = get_url("#{@url}/#{serialize(key)}")
22
26
  if val.body == ''
@@ -31,13 +35,14 @@ class Client
31
35
  end
32
36
 
33
37
  # Get all the keys as an array.
34
- #
35
- # `prefix` can be used to get all keys with a prefix.
38
+ # <tt>prefix</tt> can be used to get all keys with a prefix.
39
+ # @param prefix [String, nil] Get all keys with <tt>prefix</tt> at the start.
36
40
  def keys(prefix = '')
37
41
  get_url("#{@url}?prefix=#{prefix}").body.split("\n").map { |k| deserialize(k) }
38
42
  end
39
43
 
40
- # Deletes `key`.
44
+ # Deletes <tt>key</tt>.
45
+ # @param key [String]
41
46
  def del(key)
42
47
  uri = URI.parse("#{@url}/#{serialize(key)}")
43
48
  req = Net::HTTP::Delete.new(uri.path)
@@ -52,9 +57,9 @@ class Client
52
57
  keys.each { |k| del(k) }
53
58
  end
54
59
 
55
- # This will append `hash`.
56
- #
60
+ # This will append <tt>hash</tt>.
57
61
  # **This will NOT replace existing keys!**
62
+ # @param hash [Hash]
58
63
  def set_hash(hash)
59
64
  if hash.is_a? Hash
60
65
  hash.each { |k, v| set(k, v) }
@@ -71,9 +76,10 @@ class Client
71
76
  o
72
77
  end
73
78
 
74
- # Check if `key` exists.
79
+ # Check if <tt>key</tt> exists.
80
+ # @param key [String]
75
81
  def exists?(key)
76
- not get(key).nil?
82
+ !get(key).nil?
77
83
  end
78
84
 
79
85
  # internals
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repldb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coder100