state_mate 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6405979811d0c551cc74702afc8e4b32b17a7947
4
- data.tar.gz: d5832875e024eb641f188c9d1cfc5ceb574b0261
3
+ metadata.gz: 5f01f81ae28c991389d0bb58e43f41fb551a690b
4
+ data.tar.gz: 0e888f119ce00d45046ec008aa63d43784b0ff52
5
5
  SHA512:
6
- metadata.gz: f6d84cdcff0f671d9db98c1a2e27faf6bda37c181ca7ba3039c87196c0b38cf53daa59d9ad7b551a03d12b46f60d687614ca6b2b48036ac2776c8f76077fb6a8
7
- data.tar.gz: e76937841bc8713c17c8390b06b35f6f2af1f62b9686499199fbb93366302530bbec05e9e73e4437404fea750c99746c35aaf3041847259d361e94736943dedf
6
+ metadata.gz: 3a3d7f7027493edc8aace942eb0cb15888a0145d500252f36e0d05edee3d953f4312fa009fdbb87cf9c6b86c45bee5ba177bdbb4540a3492e0284711b9979e1c
7
+ data.tar.gz: 1d4fbf23716276cb3688e7d73165802c20a4f4445cf688bd2ced4a3b64d2a52ec8e0ffacabcb82b9768de76846b3b7978f8b36a3dc0ebaeef59bf20e6e3481e6
@@ -13,10 +13,48 @@ module StateMate
13
13
  @debug_mode = 'a'
14
14
 
15
15
  DIRECTIVES = Set.new [
16
+ # ensures that the key is set to the provided value
16
17
  :set,
18
+
19
+ # ensures that the key is absent
17
20
  :unset,
21
+
22
+ # ensures that the key is an array containing the provided items.
23
+ #
24
+ # if the key is missing and `create` or `clobber` options evaluate true, it
25
+ # will be created to have exactly the provided items. otherwise it will
26
+ # fail.
27
+ #
28
+ # if the value is not an array and `clobber` option evaluates true it will
29
+ # be replaced with an array of exactly the provided items. otherwise it
30
+ # will fail.
31
+ #
18
32
  :array_contains,
33
+
34
+ # ensures that the value is an array that is missing the provided items.
35
+ #
36
+ # if the current value is:
37
+ #
38
+ # - missing/nil/null:
39
+ # - if the `unset_ok` option evaluates **true**:
40
+ # - it will validate as a correct state and no action will be
41
+ # taken.
42
+ # - **NOTE: this is the ONLY case where the action succeeds
43
+ # and the value IS NOT an array afterwards**.
44
+ # - if the `unset_ok` option evaluates **false** (default):
45
+ # - if the `create` or `clobber` options evaluate **true**:
46
+ # - the value will be set to an empty array.
47
+ # - otherwise:
48
+ # - fails.
49
+ # - something else that's not an array:
50
+ # - if the `clobber` option evaluates **true**:
51
+ # - value will be set to an empty array.
52
+ # - if the `clobber` option evaluates **false** (default):
53
+ # - fails.
19
54
  :array_missing,
55
+
56
+ # initializes a value - setting it only if it is missing/nil
57
+ :init,
20
58
  ]
21
59
 
22
60
  class StateSet
@@ -112,7 +150,7 @@ module StateMate
112
150
  unset_when = StateMate.cast 'bool', v
113
151
  else
114
152
  # any other keys are set as options
115
- # this is a little convience feature that avoids having to
153
+ # this is a little convenience feature that avoids having to
116
154
  # nest inside an `options` key unless your option conflicts
117
155
  # with 'key' or a directive.
118
156
  #
@@ -143,7 +181,7 @@ module StateMate
143
181
  end
144
182
 
145
183
  # handle :unset_when_false option, which changes the operation to
146
- # an unset when the *directive value* is explicity false
184
+ # an unset when the *directive value* is explicitly false
147
185
  if unset_when_false &&
148
186
  (value === false || ['False', 'false'].include?(value))
149
187
  directive = :unset
@@ -485,7 +523,7 @@ module StateMate
485
523
 
486
524
  # @param options [Hash]
487
525
  # @option options [Boolean] :unset_ok if true, the value being unset is
488
- # acceptible. many plist files will simply omit the key rather than
526
+ # acceptable. many plist files will simply omit the key rather than
489
527
  # store an empty array in the case that an array value is empty,
490
528
  # and setting these to an empty array when all we want to do is make
491
529
  # sure that *if it is there, it doesn't contain the value* seems
@@ -541,5 +579,15 @@ module StateMate
541
579
  end
542
580
  end # case current
543
581
  end # array_missing
582
+
583
+ # the value is initialized if it's currently not nil
584
+ def self.init? key, current, value, adapter, options
585
+ return !current.nil?
586
+ end
587
+
588
+ # when a value needs to be initialized it is simply set to the value.
589
+ def self.init key, current, value, options
590
+ return value
591
+ end
544
592
 
545
593
  end # StateMate
@@ -1,3 +1,3 @@
1
1
  module StateMate
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_mate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-20 00:00:00.000000000 Z
11
+ date: 2016-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler