knot-ruby 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/knot/interface.rb +32 -6
- data/lib/knot/protocol.rb +5 -5
- data/lib/knot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d24b7dfed91ed556ec5c2ee1b6c765eb96879e2d7d5fdd4dfaf060e474f4c91
|
4
|
+
data.tar.gz: 66c899d76cbd7ff9ea68d7f3f0fad98dc8bf21a1e136d156379f25ee42046ad1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5763ee24991d9d75ef48da2bb203acba69dc89dc4d982d35abd23980792f0649062ef4e58b8a9f5982a341cda9c20ac810873de1476d057c69cc733105fa5ecc
|
7
|
+
data.tar.gz: b932a258e7340a0e3baa7a0a833868b6a5a9ae8eb6f5d1149601193238c1279abe3710d3dda9e1e5cc193ba74baa3fad61411ad34820b60fdffca52d6a7035f5
|
data/lib/knot/interface.rb
CHANGED
@@ -11,22 +11,35 @@ class Knot::Zone
|
|
11
11
|
@zone, @transaction_opened = zone, 0
|
12
12
|
end
|
13
13
|
|
14
|
+
# If no transaction opened, yet, it opens a new transaction.
|
15
|
+
# Counts calling begin.
|
16
|
+
# Knot allowes only one global transaction, so if two clients tries to open a transaction,
|
17
|
+
# the second will fail. But the second client can change items in the same
|
18
|
+
# transaction like the first client.
|
19
|
+
# The first client, which calls commit or abort, wins and the transaction will be closed.
|
20
|
+
# So, the transaction-handling is only safe, if one client connects to knot.
|
14
21
|
def begin
|
15
22
|
@transaction_opened += 1
|
16
23
|
@protocol.call command: 'zone-begin', zone: @zone if 1 == @transaction_opened
|
17
24
|
end
|
18
25
|
|
26
|
+
# Decreases opened transactions.
|
27
|
+
# If opened transactions is zero, it stores items and closes transaction successfully.
|
19
28
|
def commit
|
20
29
|
@protocol.call command: 'zone-commit', zone: @zone if 1 == @transaction_opened
|
21
30
|
@transaction_opened -= 1 if 0 < @transaction_opened
|
22
31
|
end
|
23
32
|
|
33
|
+
# Closes transaction without saving immidiatly.
|
34
|
+
# Counter of opened transaction will be reset to 0.
|
24
35
|
def abort
|
25
36
|
@protocol.call command: 'zone-abort', zone: @zone
|
26
37
|
@transaction_opened = 0
|
27
38
|
end
|
28
39
|
|
29
|
-
|
40
|
+
# Opens transaction, calls yielded Proc and closes transaction after return.
|
41
|
+
# If exception was raised, the transaction will be aborted.
|
42
|
+
def transaction # :yield:
|
30
43
|
self.begin
|
31
44
|
yield self
|
32
45
|
rescue Object
|
@@ -72,6 +85,7 @@ class Knot::Zone
|
|
72
85
|
rescue Knot::Errors::ENONODE, Knot::Errors::ENOENT
|
73
86
|
end
|
74
87
|
alias delete unset
|
88
|
+
alias del unset
|
75
89
|
|
76
90
|
def get owner = nil, type = nil
|
77
91
|
@protocol.call command: 'zone-get',
|
@@ -115,10 +129,12 @@ class Knot::Conf
|
|
115
129
|
|
116
130
|
def parse_item k
|
117
131
|
case k
|
118
|
-
when
|
132
|
+
when Hash
|
119
133
|
case k.keys.sort
|
120
|
-
when %w[section], %w[id section], %w[item section], %w[id item section]
|
121
|
-
|
134
|
+
when %w[section], %w[id section], %w[item section], %w[id item section]
|
135
|
+
k
|
136
|
+
else
|
137
|
+
raise ArgumentError, "Invalid Item-format"
|
122
138
|
end
|
123
139
|
|
124
140
|
when Array
|
@@ -134,16 +150,26 @@ class Knot::Conf
|
|
134
150
|
(?: \[ (?<id> [a-z0-9_.-]+) \] )?
|
135
151
|
(?: \. (?<item>[a-z0-9_-]+) )?
|
136
152
|
\z/xi
|
153
|
+
|
137
154
|
$~.named_captures.delete_if {|_,v| v.nil? }
|
138
|
-
|
155
|
+
|
156
|
+
else
|
157
|
+
raise ArgumentError, "Invalid Item-format"
|
139
158
|
end
|
140
159
|
end
|
141
160
|
|
161
|
+
def get item = nil
|
162
|
+
@protocol.call (item ? parse_item( item) : {}).update( command: 'conf-get')
|
163
|
+
end
|
164
|
+
|
165
|
+
# Sets or adds a new value to item.
|
166
|
+
# knot knows single-value items like `server.rundir` and multi-value items like `server.listen`.
|
167
|
+
# If you set a single-value, it will replace the old value. On a multi-value, it will add it.
|
142
168
|
def set item, value
|
143
169
|
@protocol.call parse_item( item).update( command: 'conf-set', data: value)
|
144
170
|
end
|
145
|
-
alias [] set
|
146
171
|
|
172
|
+
# Removes value from item. If you provide a value, this value will be removed.
|
147
173
|
def unset item, value = nil
|
148
174
|
@protocol.call parse_item( item).update( command: 'conf-unset', data: value)
|
149
175
|
end
|
data/lib/knot/protocol.rb
CHANGED
@@ -179,10 +179,10 @@ class Knot::Protocol
|
|
179
179
|
|
180
180
|
def zone( zone) @zones[zone.to_s.to_sym] end
|
181
181
|
|
182
|
-
def conf_set( **opts) call opts.update( command: 'conf-set') end
|
183
|
-
def conf_unset( **opts) call opts.update( command: 'conf-set') end
|
182
|
+
def conf_set( **opts) call **opts.update( command: 'conf-set') end
|
183
|
+
def conf_unset( **opts) call **opts.update( command: 'conf-set') end
|
184
184
|
|
185
|
-
def zone_set( **opts) call opts.update( command: 'zone-set') end
|
186
|
-
def zone_unset( **opts) call opts.update( command: 'zone-unset') end
|
187
|
-
def zone_get( **opts) call opts.update( command: 'zone-get') end
|
185
|
+
def zone_set( **opts) call **opts.update( command: 'zone-set') end
|
186
|
+
def zone_unset( **opts) call **opts.update( command: 'zone-unset') end
|
187
|
+
def zone_get( **opts) call **opts.update( command: 'zone-get') end
|
188
188
|
end
|
data/lib/knot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knot-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Knauf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iounpack
|