jylis-rb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,7 +60,7 @@
60
60
  <div id="content"><div id='filecontents'>The MIT License (MIT)<br/><br/>Copyright (c) 2018 Alex McLain<br/><br/>Permission is hereby granted, free of charge, to any person obtaining a copy<br/>of this software and associated documentation files (the &quot;Software&quot;), to deal<br/>in the Software without restriction, including without limitation the rights<br/>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br/>copies of the Software, and to permit persons to whom the Software is<br/>furnished to do so, subject to the following conditions:<br/><br/>The above copyright notice and this permission notice shall be included in<br/>all copies or substantial portions of the Software.<br/><br/>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br/>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br/>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br/>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br/>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br/>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br/>THE SOFTWARE.</div></div>
61
61
 
62
62
  <div id="footer">
63
- Generated on Sun Jun 3 21:46:59 2018 by
63
+ Generated on Tue Jun 5 17:01:51 2018 by
64
64
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
65
65
  0.9.14 (ruby-2.5.1).
66
66
  </div>
data/doc/index.html CHANGED
@@ -118,7 +118,7 @@ $ cd jylis-rb
118
118
 
119
119
  <p>Ensure the tests pass:</p>
120
120
 
121
- <pre class="code ruby"><code class="ruby">$ rake
121
+ <pre class="code ruby"><code class="ruby">$ bundle exec rake
122
122
  </code></pre>
123
123
 
124
124
  <p>Install the gem from the working source code:</p>
@@ -258,9 +258,9 @@ for the exact format of your particular query.</p>
258
258
  <p>Unordered JSON
259
259
  &lt;sup>[link[https://jemc.github.io/jylis/docs/types/ujson/]]</sup&gt;</p>
260
260
 
261
- <pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ujson'><span class='object_link'><a href="Jylis.html#ujson-class_method" title="Jylis.ujson (method)">ujson</a></span></span><span class='period'>.</span><span class='id identifier rubyid_set'><span class='object_link'><a href="Jylis/DataType/UJSON.html#set-instance_method" title="Jylis::DataType::UJSON#set (method)">set</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>users</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>alice</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>admin</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='kw'>false</span>
262
- <span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ujson'><span class='object_link'><a href="Jylis.html#ujson-class_method" title="Jylis.ujson (method)">ujson</a></span></span><span class='period'>.</span><span class='id identifier rubyid_set'><span class='object_link'><a href="Jylis/DataType/UJSON.html#set-instance_method" title="Jylis::DataType::UJSON#set (method)">set</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>users</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>brett</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>admin</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='kw'>false</span>
263
- <span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ujson'><span class='object_link'><a href="Jylis.html#ujson-class_method" title="Jylis.ujson (method)">ujson</a></span></span><span class='period'>.</span><span class='id identifier rubyid_set'><span class='object_link'><a href="Jylis/DataType/UJSON.html#set-instance_method" title="Jylis::DataType::UJSON#set (method)">set</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>users</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>carol</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>admin</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='kw'>true</span>
261
+ <pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ujson'><span class='object_link'><a href="Jylis.html#ujson-class_method" title="Jylis.ujson (method)">ujson</a></span></span><span class='period'>.</span><span class='id identifier rubyid_set'><span class='object_link'><a href="Jylis/DataType/UJSON.html#set-instance_method" title="Jylis::DataType::UJSON#set (method)">set</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>users</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>alice</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>admin</span><span class='label_end'>&quot;:</span> <span class='kw'>false</span><span class='rbrace'>}</span>
262
+ <span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ujson'><span class='object_link'><a href="Jylis.html#ujson-class_method" title="Jylis.ujson (method)">ujson</a></span></span><span class='period'>.</span><span class='id identifier rubyid_set'><span class='object_link'><a href="Jylis/DataType/UJSON.html#set-instance_method" title="Jylis::DataType::UJSON#set (method)">set</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>users</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>brett</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>admin</span><span class='label_end'>&quot;:</span> <span class='kw'>false</span><span class='rbrace'>}</span>
263
+ <span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ujson'><span class='object_link'><a href="Jylis.html#ujson-class_method" title="Jylis.ujson (method)">ujson</a></span></span><span class='period'>.</span><span class='id identifier rubyid_set'><span class='object_link'><a href="Jylis/DataType/UJSON.html#set-instance_method" title="Jylis::DataType::UJSON#set (method)">set</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>users</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>carol</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>admin</span><span class='label_end'>&quot;:</span> <span class='kw'>true</span><span class='rbrace'>}</span>
264
264
 
265
265
  <span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ujson'><span class='object_link'><a href="Jylis.html#ujson-class_method" title="Jylis.ujson (method)">ujson</a></span></span><span class='period'>.</span><span class='id identifier rubyid_get'><span class='object_link'><a href="Jylis/DataType/UJSON.html#get-instance_method" title="Jylis::DataType::UJSON#get (method)">get</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>users</span><span class='tstring_end'>&quot;</span></span>
266
266
  <span class='comment'># =&gt; {&quot;brett&quot;=&gt;{&quot;admin&quot;=&gt;false}, &quot;carol&quot;=&gt;{&quot;admin&quot;=&gt;true}, &quot;alice&quot;=&gt;{&quot;admin&quot;=&gt;false}}
@@ -287,10 +287,31 @@ data.</p>
287
287
  <span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_query'><span class='object_link'><a href="Jylis.html#query-class_method" title="Jylis.query (method)">query</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>TLOG</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>GET</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>temperature</span><span class='tstring_end'>&quot;</span></span>
288
288
  <span class='comment'># =&gt; [[&quot;72.6&quot;, 5]]
289
289
  </span></code></pre>
290
+
291
+ <h3 id="label-Timestamps">Timestamps</h3>
292
+
293
+ <p>In addition to supporting integer timestamps as defined by the Jylis spec,
294
+ this library also has helpers to convert the Jylis <code>Timestamped</code>
295
+ data types to/from ISO 8601. Functions that have a <code>timestamp</code>
296
+ parameter will automatically convert an ISO 8601 string to a Unix
297
+ timestamp.</p>
298
+
299
+ <pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_treg'><span class='object_link'><a href="Jylis.html#treg-class_method" title="Jylis.treg (method)">treg</a></span></span><span class='period'>.</span><span class='id identifier rubyid_set'><span class='object_link'><a href="Jylis/DataType/TREG.html#set-instance_method" title="Jylis::DataType::TREG#set (method)">set</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>volume</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='int'>64</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>2018-06-06T01:42:57Z</span><span class='tstring_end'>&quot;</span></span>
300
+
301
+ <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Jylis.html" title="Jylis (class)">Jylis</a></span></span><span class='period'>.</span><span class='id identifier rubyid_treg'><span class='object_link'><a href="Jylis.html#treg-class_method" title="Jylis.treg (method)">treg</a></span></span><span class='period'>.</span><span class='id identifier rubyid_get'><span class='object_link'><a href="Jylis/DataType/TREG.html#get-instance_method" title="Jylis::DataType::TREG#get (method)">get</a></span></span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>volume</span><span class='tstring_end'>&quot;</span></span>
302
+ <span class='comment'># =&gt; #&lt;Jylis::DataType::TREG::Result:0x00005609aa767f00 @timestamp=1528249377, @value=&quot;64&quot;&gt;
303
+ </span>
304
+ <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_timestamp'>timestamp</span>
305
+ <span class='comment'># =&gt; 1528249377
306
+ </span><span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_time'>time</span>
307
+ <span class='comment'># =&gt; 2018-06-05 18:42:57 -0700
308
+ </span><span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_timestamp_iso8601'>timestamp_iso8601</span>
309
+ <span class='comment'># =&gt; &quot;2018-06-06T01:42:57Z&quot;
310
+ </span></code></pre>
290
311
  </div></div>
291
312
 
292
313
  <div id="footer">
293
- Generated on Sun Jun 3 21:46:59 2018 by
314
+ Generated on Tue Jun 5 17:01:51 2018 by
294
315
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
295
316
  0.9.14 (ruby-2.5.1).
296
317
  </div>
data/doc/method_list.html CHANGED
@@ -436,6 +436,22 @@
436
436
  </li>
437
437
 
438
438
 
439
+ <li class="even ">
440
+ <div class="item">
441
+ <span class='object_link'><a href="Jylis/DataType/TLOG/Row.html#time-instance_method" title="Jylis::DataType::TLOG::Row#time (method)">#time</a></span>
442
+ <small>Jylis::DataType::TLOG::Row</small>
443
+ </div>
444
+ </li>
445
+
446
+
447
+ <li class="odd ">
448
+ <div class="item">
449
+ <span class='object_link'><a href="Jylis/DataType/TREG/Result.html#time-instance_method" title="Jylis::DataType::TREG::Result#time (method)">#time</a></span>
450
+ <small>Jylis::DataType::TREG::Result</small>
451
+ </div>
452
+ </li>
453
+
454
+
439
455
  <li class="even ">
440
456
  <div class="item">
441
457
  <span class='object_link'><a href="Jylis/DataType/TLOG/Row.html#timestamp-instance_method" title="Jylis::DataType::TLOG::Row#timestamp (method)">#timestamp</a></span>
@@ -452,6 +468,22 @@
452
468
  </li>
453
469
 
454
470
 
471
+ <li class="even ">
472
+ <div class="item">
473
+ <span class='object_link'><a href="Jylis/DataType/TLOG/Row.html#timestamp_iso8601-instance_method" title="Jylis::DataType::TLOG::Row#timestamp_iso8601 (method)">#timestamp_iso8601</a></span>
474
+ <small>Jylis::DataType::TLOG::Row</small>
475
+ </div>
476
+ </li>
477
+
478
+
479
+ <li class="odd ">
480
+ <div class="item">
481
+ <span class='object_link'><a href="Jylis/DataType/TREG/Result.html#timestamp_iso8601-instance_method" title="Jylis::DataType::TREG::Result#timestamp_iso8601 (method)">#timestamp_iso8601</a></span>
482
+ <small>Jylis::DataType::TREG::Result</small>
483
+ </div>
484
+ </li>
485
+
486
+
455
487
  <li class="even ">
456
488
  <div class="item">
457
489
  <span class='object_link'><a href="Jylis.html#tlog-class_method" title="Jylis.tlog (method)">tlog</a></span>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Sun Jun 3 21:46:59 2018 by
103
+ Generated on Tue Jun 5 17:01:51 2018 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.14 (ruby-2.5.1).
106
106
  </div>
@@ -76,6 +76,16 @@ class Jylis
76
76
  def to_a
77
77
  [value, timestamp]
78
78
  end
79
+
80
+ # @return [Time] the timestamp as a {Time} object
81
+ def time
82
+ Time.at(timestamp)
83
+ end
84
+
85
+ # @return [String] the timestamp as an ISO8601 formatted string
86
+ def timestamp_iso8601
87
+ time.utc.iso8601
88
+ end
79
89
  end
80
90
 
81
91
  # Get the latest `value` and `timestamp` for the register at `key`.
@@ -101,8 +111,11 @@ class Jylis
101
111
  # end
102
112
 
103
113
  # Insert a `value`/`timestamp` entry into the log at `key`.
114
+ #
115
+ # @param timestamp [Integer, String] a unix or iso8601 formatted timestamp
104
116
  def ins(key, value, timestamp)
105
- result = connection.query("TLOG", "INS", key, value, timestamp)
117
+ timestamp = Time.parse(timestamp).utc.to_i if timestamp.is_a?(String)
118
+ result = connection.query("TLOG", "INS", key, value, timestamp)
106
119
 
107
120
  unless result == "OK"
108
121
  raise "Failed: TLOG INS #{key} #{value} #{timestamp}"
@@ -121,8 +134,11 @@ class Jylis
121
134
 
122
135
  # Raise the cutoff timestamp of the log, causing any entries to be
123
136
  # discarded whose timestamp is earlier than the newly given `timestamp`.
137
+ #
138
+ # @param timestamp [Integer, String] a unix or iso8601 formatted timestamp
124
139
  def trimat(key, timestamp)
125
- result = connection.query("TLOG", "TRIMAT", key, timestamp)
140
+ timestamp = Time.parse(timestamp).utc.to_i if timestamp.is_a?(String)
141
+ result = connection.query("TLOG", "TRIMAT", key, timestamp)
126
142
 
127
143
  unless result == "OK"
128
144
  raise "Failed: TLOG TRIMAT #{key} #{timestamp}"
@@ -33,6 +33,16 @@ class Jylis
33
33
  def to_a
34
34
  [value, timestamp]
35
35
  end
36
+
37
+ # @return [Time] the timestamp as a {Time} object
38
+ def time
39
+ Time.at(timestamp)
40
+ end
41
+
42
+ # @return [String] the timestamp as an ISO8601 formatted string
43
+ def timestamp_iso8601
44
+ time.utc.iso8601
45
+ end
36
46
  end
37
47
 
38
48
  # Get the latest `value` and `timestamp` for the register at `key`.
@@ -45,8 +55,11 @@ class Jylis
45
55
  end
46
56
 
47
57
  # Set a `value` and `timestamp` for the register at `key`.
58
+ #
59
+ # @param timestamp [Integer, String] a unix or iso8601 formatted timestamp
48
60
  def set(key, value, timestamp)
49
- result = connection.query("TREG", "SET", key, value, timestamp)
61
+ timestamp = Time.parse(timestamp).utc.to_i if timestamp.is_a?(String)
62
+ result = connection.query("TREG", "SET", key, value, timestamp)
50
63
 
51
64
  unless result == "OK"
52
65
  raise "Failed: TREG SET #{key} #{value} #{timestamp}"
@@ -23,6 +23,8 @@ class Jylis
23
23
  # @return [Boolean] true if a connection to the current server is established
24
24
  # @see Jylis::Connection#connected?
25
25
  def connected?
26
+ return false unless current
27
+
26
28
  current.connected?
27
29
  end
28
30
 
@@ -1,4 +1,4 @@
1
1
  class Jylis
2
2
  # Gem version.
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jylis-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex McLain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-03 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hiredis
@@ -152,6 +152,8 @@ files:
152
152
  - doc/Jylis/DataType/TREG.html
153
153
  - doc/Jylis/DataType/TREG/Result.html
154
154
  - doc/Jylis/DataType/UJSON.html
155
+ - doc/Jylis/Helpers.html
156
+ - doc/Jylis/Helpers/Timestamp.html
155
157
  - doc/_index.html
156
158
  - doc/class_list.html
157
159
  - doc/css/common.css