orbitalqueue 0.0.1 → 0.0.2

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 +10 -3
  3. data/lib/orbitalqueue.rb +42 -11
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1209a43eaeb6c2de53893b2c58ee64c42f7a14b8339f750443124d0a0c26fa08
4
- data.tar.gz: 9cd589726e3198cb7ab20676b7c1151eea9331106653a5ffa250c40a2adae83e
3
+ metadata.gz: d331ea29dd6bc80aa3c1127749f782845d1f23c2a9729f987af9128f1922bf21
4
+ data.tar.gz: 5f7c04a0cef45399d4726900330ac96b1714e3275545a2d1e4e209fe61aec6c9
5
5
  SHA512:
6
- metadata.gz: 9fcb2e82342484b0334fc4e95469e017ba633211547e93c4f171fbe6861d0403b22c7a07f66f14a30c3e756f455c65737671f91e6090822f51e1b91d6b38992e
7
- data.tar.gz: 9235c90069bdabbbd359499914a92599ce3782329369980e9ade49b630619f4f04abd6ebf32e19baece2c4a9b28b124f33e5c00320455361e070671f13bb6753
6
+ metadata.gz: a7d5ead3e5494a3f38808e9b363b1ceb624168e294ee6a7165630092ec3ff3a58448234f434411f865539e89d8aa5f1cdf3100adde94ca6cc26066ec5c1d0795
7
+ data.tar.gz: 7aab8b14af6f147b0b7276e37baee3db4324ca4052445c1fefcdd094f47e64e770f0a3357eec8a69d35ebbedd2263b7b3b5d208e457c73b5f6b3f34a5560ba39
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # orbital-queue
1
+ # Orbital Queue
2
2
 
3
3
  [![CI](https://github.com/reasonset/orbital-queue/actions/workflows/ci.yml/badge.svg)](https://github.com/reasonset/orbital-queue/actions/workflows/ci.yml)
4
4
 
@@ -39,11 +39,12 @@ Since enqueued objects are serialized using `Marshal` and persisted as files, ca
39
39
  require 'orbitalqueue'
40
40
 
41
41
  queue = OrbitalQueue.new("/path/to/queue")
42
- data = queue.pop
42
+ item = queue.pop
43
+ data = item.data
43
44
 
44
45
  # Something, something...
45
46
 
46
- queue.complete data[:queue_id]
47
+ item.complete
47
48
  ```
48
49
 
49
50
  Calling `#pop` retrieves a single item from the queue in no particular order.
@@ -54,3 +55,9 @@ If guaranteed completion is not required and the item should be removed immediat
54
55
 
55
56
  Both `#pop` and `#pop!` return a queue item as a `Hash`. If the original object was not a `Hash`, it will be stored under the `:data` key. Regardless of the original type, the queue ID is always stored under the `:queue_id` key.
56
57
 
58
+ # About Orbital Design
59
+
60
+ ## Description
61
+
62
+ ## Design pattern rules
63
+
data/lib/orbitalqueue.rb CHANGED
@@ -45,6 +45,8 @@ class OrbitalQueue
45
45
 
46
46
  # Pop data from queue.
47
47
  # Popped queue items are placed in the checkout directory. After processing is complete, +#complete+ must be called to remove the item from the queue.
48
+ #
49
+ # If block is given, complete automatically after yield.
48
50
  def pop
49
51
  queue_data = nil
50
52
  queue_id = nil
@@ -57,28 +59,29 @@ class OrbitalQueue
57
59
  next
58
60
  end
59
61
 
60
- queue_data = Marshal.load(File.read File.join(@queue_dir, ".checkout", File.basename(qf)))
62
+ data = Marshal.load(File.read File.join(@queue_dir, ".checkout", File.basename(qf)))
61
63
  queue_id = File.basename qf, ".marshal"
62
64
 
63
- if Hash === queue_data
64
- queue_data[:queue_id] = queue_id
65
- else
66
- queue_data = {queue_id: queue_id, data: queue_data}
67
- end
65
+ queue_data = OrbitalQueue::QueueObject.new(self, data, queue_id)
68
66
  break
69
67
  end
70
68
 
71
- queue_data
69
+ if block_given?
70
+ yield queue_data.data
71
+ complete queue_id
72
+ else
73
+ queue_data
74
+ end
72
75
  end
73
76
 
74
77
  # Pop data from queue and remove it from queue.
75
78
  def pop!
76
- queue_data = pop
77
- if queue_data
78
- complete queue_data[:queue_id]
79
+ queue_item = pop
80
+ if queue_item
81
+ queue_item.complete
79
82
  end
80
83
 
81
- queue_data
84
+ queue_item
82
85
  end
83
86
 
84
87
  # Remove checked out queue item.
@@ -92,3 +95,31 @@ class OrbitalQueue
92
95
  queue_id
93
96
  end
94
97
  end
98
+
99
+ # Queue item capsule.
100
+ class OrbitalQueue::QueueObject
101
+ def initialize(queue, data, queue_id)
102
+ @queue = queue
103
+ @data = data
104
+ @queue_id = queue_id
105
+ @completed = false
106
+ end
107
+
108
+ attr_reader :data
109
+
110
+ # Another complete interface.
111
+ def complete
112
+ if @completed
113
+ nil
114
+ else
115
+ @queue.complete(@queue_id)
116
+ @completed = true
117
+ @queue_id
118
+ end
119
+ end
120
+
121
+ # Terrible redundunt method.
122
+ def complete?
123
+ @completed
124
+ end
125
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orbitalqueue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Haruka