state_mate 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +14 -0
- data/lib/state_mate/adapters/nvram.rb +11 -15
- data/lib/state_mate/adapters/scutil.rb +59 -0
- data/lib/state_mate/version.rb +1 -1
- data/lib/state_mate.rb +72 -4
- data/state_mate.gemspec +10 -6
- metadata +23 -47
- data/spec/spec_helper.rb +0 -77
- data/spec/state_mate/adapters/defaults/hardware_uuid_spec.rb +0 -15
- data/spec/state_mate/adapters/defaults/hash_deep_write_spec.rb +0 -37
- data/spec/state_mate/adapters/defaults/read_defaults_spec.rb +0 -57
- data/spec/state_mate/adapters/defaults/read_spec.rb +0 -52
- data/spec/state_mate/adapters/defaults/read_type_spec.rb +0 -32
- data/spec/state_mate/adapters/defaults/write_spec.rb +0 -103
- data/spec/state_mate/adapters/git_config/read_spec.rb +0 -23
- data/spec/state_mate/adapters/git_config/write_spec.rb +0 -13
- data/spec/state_mate/adapters/json/read_spec.rb +0 -56
- data/spec/state_mate/adapters/json/write_spec.rb +0 -54
- data/spec/state_mate/execute_spec.rb +0 -40
- data/spec/state_mate_spec.rb +0 -7
- data/test/ansible/ansible.cfg +0 -5
- data/test/ansible/clear +0 -2
- data/test/ansible/hosts +0 -1
- data/test/ansible/play +0 -2
- data/test/ansible/playbook.yml +0 -38
- data/test/ansible/read +0 -2
- data/test/bin/install.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c226a8faea22d2b1e92ba9ec2b6a7e4bd05567d
|
4
|
+
data.tar.gz: 5a3aa7df4eaa5174c2da39cda349871f87d45d57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a5cd92203f92b5fecb9aaf63198c16d64936e151bbc5f7b050161121e6a6f7700045b9cb62cbe39deac7ceb1021e3852721829a459ba66c5f6c02409dffcac8
|
7
|
+
data.tar.gz: 9ba7d11e17927dd298e769d29692ee9257299fdde999b849549c1e7f739672cd9f8235fc3361a0decbeae6aa4f7440d7d49605c2068f9b1984c8f4217d3f3d02
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "state_mate"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
@@ -8,37 +8,33 @@ module StateMate::Adapters; end
|
|
8
8
|
|
9
9
|
module StateMate::Adapters::NVRAM
|
10
10
|
def self.read key, options = {}
|
11
|
-
|
11
|
+
result = Cmds "nvram %{key}", key: key
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
rescue SystemCallError => e
|
16
|
-
if e.message.include? "nvram: Error getting variable"
|
13
|
+
if result.error?
|
14
|
+
if result.err.start_with? "nvram: Error getting variable"
|
17
15
|
return nil
|
18
|
-
else
|
19
|
-
raise e
|
20
16
|
end
|
17
|
+
result.assert
|
21
18
|
end
|
22
19
|
|
23
|
-
if m = /^#{ key }\t(.*)\n$/.match(
|
20
|
+
if m = /^#{ key }\t(.*)\n$/.match(result.out)
|
24
21
|
m[1]
|
25
22
|
else
|
26
|
-
raise
|
23
|
+
raise binding.erb <<-BLOCK
|
27
24
|
can't parse output for key <%= key.inspect %>:
|
28
25
|
|
29
|
-
cmd: <%= cmd
|
26
|
+
cmd: <%= result.cmd %>
|
30
27
|
|
31
|
-
output: <%=
|
28
|
+
output: <%= result.out.inspect %>
|
32
29
|
BLOCK
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
36
33
|
def self.write key, value, options = {}
|
37
|
-
unless value.is_a? String
|
34
|
+
unless value.is_a? String
|
38
35
|
raise "value must be a String, not #{ value.inspect }"
|
39
36
|
end
|
40
37
|
|
41
|
-
|
42
|
-
NRSER::Exec.run cmd
|
38
|
+
Cmds! "sudo nvram #{ key }='#{ value }'"
|
43
39
|
end
|
44
|
-
end # NVRAM
|
40
|
+
end # NVRAM
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'cmds'
|
2
|
+
|
3
|
+
module StateMate; end
|
4
|
+
module StateMate::Adapters; end
|
5
|
+
|
6
|
+
# adapter to set global git config options
|
7
|
+
module StateMate::Adapters::SCUtil
|
8
|
+
|
9
|
+
# @api adapter
|
10
|
+
#
|
11
|
+
# adapter API call that reads a value from scutil.
|
12
|
+
#
|
13
|
+
# @param key [String] the key to read. from `man scutil`:
|
14
|
+
#
|
15
|
+
# Supported preferences include:
|
16
|
+
#
|
17
|
+
# ComputerName The user-friendly name for the system.
|
18
|
+
#
|
19
|
+
# LocalHostName The local (Bonjour) host name.
|
20
|
+
#
|
21
|
+
# HostName The name associated with hostname(1) and gethostname(3).
|
22
|
+
#
|
23
|
+
# @param options [Hash] unused options to conform to adapter API
|
24
|
+
#
|
25
|
+
# @return [String, nil] the scutil value, or `nil` if not set.
|
26
|
+
#
|
27
|
+
# @raise [SystemCallError] if the command failed.
|
28
|
+
#
|
29
|
+
def self.read key, options = {}
|
30
|
+
result = Cmds "scutil --get %{key}", key: key
|
31
|
+
if result.ok?
|
32
|
+
result.out.chomp
|
33
|
+
else
|
34
|
+
if result.err.match /^#{ key }\:\ not set/
|
35
|
+
nil
|
36
|
+
else
|
37
|
+
result.assert
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end # ::read
|
41
|
+
|
42
|
+
|
43
|
+
# @api adapter
|
44
|
+
#
|
45
|
+
# adapter API call that writes a value to the git global config.
|
46
|
+
#
|
47
|
+
# @param key [String] the key to write
|
48
|
+
# @param value [String] the value to write
|
49
|
+
# @param options [Hash] unused options to conform to adapter API
|
50
|
+
#
|
51
|
+
# @return nil
|
52
|
+
#
|
53
|
+
def self.write key, value, options = {}
|
54
|
+
Cmds! "sudo scutil --set %{key} %{value}",
|
55
|
+
key: key,
|
56
|
+
value: value
|
57
|
+
nil
|
58
|
+
end # ::write
|
59
|
+
end # SCUtil
|
data/lib/state_mate/version.rb
CHANGED
data/lib/state_mate.rb
CHANGED
@@ -81,17 +81,51 @@ module StateMate
|
|
81
81
|
|
82
82
|
key = nil
|
83
83
|
directives = []
|
84
|
-
|
85
|
-
|
84
|
+
type_name = nil
|
85
|
+
options = state['options'] || {}
|
86
|
+
|
87
|
+
unless options.is_a? Hash
|
88
|
+
raise TypeError.new binding.erb <<-END
|
89
|
+
options must be a hash, found <%= options.class %>:
|
90
|
+
|
91
|
+
<%= options.inspect %>
|
92
|
+
|
93
|
+
state:
|
94
|
+
|
95
|
+
<%= state.inspect %>
|
96
|
+
|
97
|
+
END
|
98
|
+
end
|
99
|
+
|
86
100
|
state.each do |k, v|
|
87
101
|
if k == 'key'
|
88
102
|
key = v
|
89
103
|
elsif k == 'options'
|
90
|
-
|
104
|
+
# pass, dealt with above
|
91
105
|
elsif DIRECTIVES.include? k
|
92
106
|
directives << [k, v]
|
107
|
+
elsif k == 'type'
|
108
|
+
type_name = v
|
93
109
|
else
|
94
|
-
|
110
|
+
# any other keys are set as options
|
111
|
+
# this is a little convience feature that avoids having to
|
112
|
+
# nest inside an `options` key unless your option conflicts
|
113
|
+
# with 'key' or a directive.
|
114
|
+
#
|
115
|
+
# check for conflicts
|
116
|
+
if options.key? k
|
117
|
+
raise ArgumentError.new binding.erb <<-END
|
118
|
+
top-level state key #{ k.inspect } was also provided in the
|
119
|
+
options.
|
120
|
+
|
121
|
+
state:
|
122
|
+
|
123
|
+
<%= state.inspect %>
|
124
|
+
|
125
|
+
END
|
126
|
+
end
|
127
|
+
|
128
|
+
options[k] = v
|
95
129
|
end
|
96
130
|
end
|
97
131
|
|
@@ -103,6 +137,10 @@ module StateMate
|
|
103
137
|
else
|
104
138
|
raise "multiple directives found in #{ state.inspect }"
|
105
139
|
end
|
140
|
+
|
141
|
+
unless type_name.nil?
|
142
|
+
value = StateMate.cast type_name, value
|
143
|
+
end
|
106
144
|
|
107
145
|
state_set.add adapter, key, directive, value, options
|
108
146
|
end # state.each
|
@@ -246,6 +284,36 @@ module StateMate
|
|
246
284
|
end
|
247
285
|
end # rollback
|
248
286
|
end # StateSet
|
287
|
+
|
288
|
+
# @api util
|
289
|
+
# *pure*
|
290
|
+
#
|
291
|
+
# casts a value to a type, or raises an error if not possible.
|
292
|
+
# this is useful because ansible in particular likes to pass things
|
293
|
+
# as strings.
|
294
|
+
#
|
295
|
+
# @param type_name [String] the 'name' of the type to cast to.
|
296
|
+
|
297
|
+
def self.cast type_name, value
|
298
|
+
case type_name
|
299
|
+
when 'string', 'str'
|
300
|
+
value.to_s
|
301
|
+
when 'integer', 'int'
|
302
|
+
value.to_i
|
303
|
+
when 'float'
|
304
|
+
value.to_f
|
305
|
+
when 'boolean', 'bool'
|
306
|
+
if value.to_s.downcase == 'true'
|
307
|
+
true
|
308
|
+
elsif value.to_s.downcase == 'false'
|
309
|
+
false
|
310
|
+
else
|
311
|
+
raise ArgumentError.new "can't cast to boolean: #{ value.inspect }"
|
312
|
+
end
|
313
|
+
else
|
314
|
+
raise ArgumentError.new "bad type name: #{ type_name.inspect }"
|
315
|
+
end
|
316
|
+
end
|
249
317
|
|
250
318
|
def self.get_adapter adapter_name
|
251
319
|
begin
|
data/state_mate.gemspec
CHANGED
@@ -9,12 +9,16 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["nrser"]
|
10
10
|
spec.email = ["neil@ztkae.com"]
|
11
11
|
spec.summary = %q{i heard it's meant to help you with your state, mate!}
|
12
|
+
spec.description = <<-END
|
13
|
+
helps manage state on OSX by wrapping system commands like `defaults`, `nvram`,
|
14
|
+
`lanuchctl`, `scutil` and more.
|
15
|
+
END
|
12
16
|
spec.homepage = "https://github.com/nrser/state_mate"
|
13
17
|
spec.license = "MIT"
|
14
18
|
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
16
|
-
spec.
|
17
|
-
spec.
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
22
|
spec.require_paths = ["lib"]
|
19
23
|
|
20
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
@@ -22,8 +26,8 @@ Gem::Specification.new do |spec|
|
|
22
26
|
spec.add_development_dependency "rspec"
|
23
27
|
spec.add_development_dependency "yard"
|
24
28
|
spec.add_development_dependency "redcarpet"
|
25
|
-
|
26
|
-
spec.add_dependency 'nrser', '>= 0.0.13'
|
29
|
+
|
30
|
+
spec.add_dependency 'nrser', '~> 0.0', '>= 0.0.13'
|
27
31
|
spec.add_dependency 'CFPropertyList', '~> 2.3'
|
28
|
-
spec.add_dependency 'cmds', '>= 0.0.
|
32
|
+
spec.add_dependency 'cmds', '~> 0.0', '>= 0.0.9'
|
29
33
|
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.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,9 @@ dependencies:
|
|
84
84
|
name: nrser
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.0'
|
87
90
|
- - ">="
|
88
91
|
- !ruby/object:Gem::Version
|
89
92
|
version: 0.0.13
|
@@ -91,6 +94,9 @@ dependencies:
|
|
91
94
|
prerelease: false
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.0'
|
94
100
|
- - ">="
|
95
101
|
- !ruby/object:Gem::Version
|
96
102
|
version: 0.0.13
|
@@ -112,17 +118,25 @@ dependencies:
|
|
112
118
|
name: cmds
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
114
120
|
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.0'
|
115
124
|
- - ">="
|
116
125
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.0.
|
126
|
+
version: 0.0.9
|
118
127
|
type: :runtime
|
119
128
|
prerelease: false
|
120
129
|
version_requirements: !ruby/object:Gem::Requirement
|
121
130
|
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0.0'
|
122
134
|
- - ">="
|
123
135
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.0.
|
125
|
-
description:
|
136
|
+
version: 0.0.9
|
137
|
+
description: |
|
138
|
+
helps manage state on OSX by wrapping system commands like `defaults`, `nvram`,
|
139
|
+
`lanuchctl`, `scutil` and more.
|
126
140
|
email:
|
127
141
|
- neil@ztkae.com
|
128
142
|
executables: []
|
@@ -137,36 +151,18 @@ files:
|
|
137
151
|
- README.md
|
138
152
|
- Rakefile
|
139
153
|
- ansible/library/state
|
154
|
+
- bin/console
|
140
155
|
- lib/state_mate.rb
|
141
156
|
- lib/state_mate/adapters/defaults.rb
|
142
157
|
- lib/state_mate/adapters/git_config.rb
|
143
158
|
- lib/state_mate/adapters/json.rb
|
144
159
|
- lib/state_mate/adapters/launchd.rb
|
145
160
|
- lib/state_mate/adapters/nvram.rb
|
161
|
+
- lib/state_mate/adapters/scutil.rb
|
146
162
|
- lib/state_mate/adapters/time_machine.rb
|
147
163
|
- lib/state_mate/version.rb
|
148
164
|
- notes/state-set-steps.md
|
149
|
-
- spec/spec_helper.rb
|
150
|
-
- spec/state_mate/adapters/defaults/hardware_uuid_spec.rb
|
151
|
-
- spec/state_mate/adapters/defaults/hash_deep_write_spec.rb
|
152
|
-
- spec/state_mate/adapters/defaults/read_defaults_spec.rb
|
153
|
-
- spec/state_mate/adapters/defaults/read_spec.rb
|
154
|
-
- spec/state_mate/adapters/defaults/read_type_spec.rb
|
155
|
-
- spec/state_mate/adapters/defaults/write_spec.rb
|
156
|
-
- spec/state_mate/adapters/git_config/read_spec.rb
|
157
|
-
- spec/state_mate/adapters/git_config/write_spec.rb
|
158
|
-
- spec/state_mate/adapters/json/read_spec.rb
|
159
|
-
- spec/state_mate/adapters/json/write_spec.rb
|
160
|
-
- spec/state_mate/execute_spec.rb
|
161
|
-
- spec/state_mate_spec.rb
|
162
165
|
- state_mate.gemspec
|
163
|
-
- test/ansible/ansible.cfg
|
164
|
-
- test/ansible/clear
|
165
|
-
- test/ansible/hosts
|
166
|
-
- test/ansible/play
|
167
|
-
- test/ansible/playbook.yml
|
168
|
-
- test/ansible/read
|
169
|
-
- test/bin/install.rb
|
170
166
|
homepage: https://github.com/nrser/state_mate
|
171
167
|
licenses:
|
172
168
|
- MIT
|
@@ -191,25 +187,5 @@ rubygems_version: 2.2.2
|
|
191
187
|
signing_key:
|
192
188
|
specification_version: 4
|
193
189
|
summary: i heard it's meant to help you with your state, mate!
|
194
|
-
test_files:
|
195
|
-
- spec/spec_helper.rb
|
196
|
-
- spec/state_mate/adapters/defaults/hardware_uuid_spec.rb
|
197
|
-
- spec/state_mate/adapters/defaults/hash_deep_write_spec.rb
|
198
|
-
- spec/state_mate/adapters/defaults/read_defaults_spec.rb
|
199
|
-
- spec/state_mate/adapters/defaults/read_spec.rb
|
200
|
-
- spec/state_mate/adapters/defaults/read_type_spec.rb
|
201
|
-
- spec/state_mate/adapters/defaults/write_spec.rb
|
202
|
-
- spec/state_mate/adapters/git_config/read_spec.rb
|
203
|
-
- spec/state_mate/adapters/git_config/write_spec.rb
|
204
|
-
- spec/state_mate/adapters/json/read_spec.rb
|
205
|
-
- spec/state_mate/adapters/json/write_spec.rb
|
206
|
-
- spec/state_mate/execute_spec.rb
|
207
|
-
- spec/state_mate_spec.rb
|
208
|
-
- test/ansible/ansible.cfg
|
209
|
-
- test/ansible/clear
|
210
|
-
- test/ansible/hosts
|
211
|
-
- test/ansible/play
|
212
|
-
- test/ansible/playbook.yml
|
213
|
-
- test/ansible/read
|
214
|
-
- test/bin/install.rb
|
190
|
+
test_files: []
|
215
191
|
has_rdoc:
|
data/spec/spec_helper.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
-
require 'state_mate'
|
5
|
-
|
6
|
-
DOMAIN = 'com.nrser.state_mate'
|
7
|
-
|
8
|
-
class MockError < StandardError; end
|
9
|
-
|
10
|
-
shared_context "#{ DOMAIN } empty" do
|
11
|
-
before(:each) {
|
12
|
-
`defaults delete #{ DOMAIN } 2>&1 > /dev/null`
|
13
|
-
`defaults -currentHost delete #{ DOMAIN } 2>&1 > /dev/null`
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
shared_context "defaults" do
|
18
|
-
let(:defaults) {
|
19
|
-
StateMate::Adapters::Defaults
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
shared_context "git_config" do
|
24
|
-
let(:git_config) {
|
25
|
-
StateMate::Adapters::GitConfig
|
26
|
-
}
|
27
|
-
|
28
|
-
let(:section) {
|
29
|
-
"statemate"
|
30
|
-
}
|
31
|
-
|
32
|
-
let(:key) {
|
33
|
-
"#{ section }.test"
|
34
|
-
}
|
35
|
-
|
36
|
-
before(:each) {
|
37
|
-
`git config --global --unset-all #{ key } 2>&1`
|
38
|
-
}
|
39
|
-
|
40
|
-
after(:each) {
|
41
|
-
`git config --global --unset-all #{ key } 2>&1`
|
42
|
-
`git config --global --remove-section #{ section } 2>&1`
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
shared_context "json" do
|
47
|
-
let(:json) {
|
48
|
-
StateMate::Adapters::JSON
|
49
|
-
}
|
50
|
-
|
51
|
-
before(:each) {
|
52
|
-
@f = Tempfile.new "state_mate_json_spec"
|
53
|
-
@filepath = @f.path
|
54
|
-
}
|
55
|
-
|
56
|
-
after(:each) {
|
57
|
-
@f.close
|
58
|
-
@f.unlink
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
def expect_defaults_read key, matcher, type
|
63
|
-
expect( `defaults read #{ DOMAIN } #{ key.shellescape }`.chomp ).to matcher
|
64
|
-
expect(
|
65
|
-
`defaults read-type #{ DOMAIN } #{ key.shellescape }`.chomp
|
66
|
-
).to eq "Type is #{ type }"
|
67
|
-
end
|
68
|
-
|
69
|
-
def remove_whitepsace str
|
70
|
-
str.gsub /[[:space:]]/, ''
|
71
|
-
end
|
72
|
-
|
73
|
-
RSpec::Matchers.define :struct_eq do |expected|
|
74
|
-
match do |actual|
|
75
|
-
remove_whitepsace(actual) == remove_whitepsace(expected)
|
76
|
-
end
|
77
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate/adapters/defaults'
|
4
|
-
|
5
|
-
describe "StateMate::Adapters::Defaults.hardware_uuid" do
|
6
|
-
let(:defaults) {
|
7
|
-
StateMate::Adapters::Defaults
|
8
|
-
}
|
9
|
-
|
10
|
-
it "returns something that looks like an apple hardware uuid" do
|
11
|
-
expect( defaults.hardware_uuid ).to(
|
12
|
-
match /[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{12}/
|
13
|
-
)
|
14
|
-
end
|
15
|
-
end # hardware_uuid
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate/adapters/defaults'
|
4
|
-
|
5
|
-
describe "StateMate::Adapters::Defaults.hash_deep_write!" do
|
6
|
-
let(:defaults) {
|
7
|
-
StateMate::Adapters::Defaults
|
8
|
-
}
|
9
|
-
|
10
|
-
it "does a basic set on an empty hash" do
|
11
|
-
h = {}
|
12
|
-
defaults.hash_deep_write! h, [:x], 1
|
13
|
-
expect( h ).to eq({x: 1})
|
14
|
-
end
|
15
|
-
|
16
|
-
it "does a deep set on an empty hash" do
|
17
|
-
h = {}
|
18
|
-
defaults.hash_deep_write! h, [:x, :y], 1
|
19
|
-
expect( h ).to eq({x: {y: 1}})
|
20
|
-
end
|
21
|
-
|
22
|
-
it "does a deep set on an non-empty hash" do
|
23
|
-
h = {a: 1}
|
24
|
-
defaults.hash_deep_write! h, [:x, :y], 1
|
25
|
-
expect( h ).to eq({a: 1, x: {y: 1}})
|
26
|
-
end
|
27
|
-
|
28
|
-
it "clobbers values" do
|
29
|
-
h = {x: [1, 2, 3]}
|
30
|
-
defaults.hash_deep_write! h, [:x, :y], 1
|
31
|
-
expect( h ).to eq({x: {y: 1}})
|
32
|
-
|
33
|
-
h = {x: 'ex'}
|
34
|
-
defaults.hash_deep_write! h, [:x, :y, :z], 1
|
35
|
-
expect( h ).to eq({x: {y: {z: 1}}})
|
36
|
-
end
|
37
|
-
end # hardware_uuid
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate/adapters/defaults'
|
4
|
-
|
5
|
-
describe "StateMate::Adapters::Defaults.read_defaults" do
|
6
|
-
include_context "defaults"
|
7
|
-
include_context "#{ DOMAIN } empty"
|
8
|
-
|
9
|
-
let(:key) {
|
10
|
-
'x'
|
11
|
-
}
|
12
|
-
|
13
|
-
it "returns an empty hash when the domain is empty" do
|
14
|
-
expect( defaults.read_defaults DOMAIN ).to eq({})
|
15
|
-
end
|
16
|
-
|
17
|
-
context "string value" do
|
18
|
-
|
19
|
-
let(:string) {
|
20
|
-
'en_US@currency=USD'
|
21
|
-
}
|
22
|
-
|
23
|
-
before(:each) {
|
24
|
-
`defaults write #{ DOMAIN } #{ key } -string '#{ string }'`
|
25
|
-
}
|
26
|
-
|
27
|
-
it "reads the domain with a string in it" do
|
28
|
-
expect( defaults.read_defaults DOMAIN ).to eq({key => string})
|
29
|
-
end
|
30
|
-
|
31
|
-
it "still reads the current host domain as empty" do
|
32
|
-
expect( defaults.read_defaults DOMAIN, true ).to eq({})
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
context "string value in current host" do
|
38
|
-
|
39
|
-
let(:string) {
|
40
|
-
'en_US@currency=USD'
|
41
|
-
}
|
42
|
-
|
43
|
-
before(:each) {
|
44
|
-
`defaults -currentHost write #{ DOMAIN } #{ key } -string '#{ string }'`
|
45
|
-
}
|
46
|
-
|
47
|
-
it "reads the domain with a string in it" do
|
48
|
-
expect( defaults.read_defaults DOMAIN, true ).to eq({key => string})
|
49
|
-
end
|
50
|
-
|
51
|
-
it "still reads the current host domain as empty" do
|
52
|
-
expect( defaults.read_defaults DOMAIN, false ).to eq({})
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate/adapters/defaults'
|
4
|
-
|
5
|
-
describe "StateMate::Adapters::Defaults.read" do
|
6
|
-
include_context "defaults"
|
7
|
-
include_context "#{ DOMAIN } empty"
|
8
|
-
|
9
|
-
let(:key) {
|
10
|
-
'x'
|
11
|
-
}
|
12
|
-
|
13
|
-
it "returns nil when the key is missing" do
|
14
|
-
expect( defaults.read [DOMAIN, key] ).to be nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "reads boolean values as a booleans (not ints)" do
|
18
|
-
bools = {
|
19
|
-
't' => [true, 1],
|
20
|
-
'f' => [false, 0],
|
21
|
-
}
|
22
|
-
|
23
|
-
bools.each {|key, (bool, int)|
|
24
|
-
# write boolean values
|
25
|
-
`defaults write #{ DOMAIN } #{ key } -boolean #{ bool }`
|
26
|
-
|
27
|
-
# when it's read by `defaults read`, it says it's a boolean
|
28
|
-
# but it returns it as an integer
|
29
|
-
expect_defaults_read key, eq(int.to_s), 'boolean'
|
30
|
-
|
31
|
-
# however, since we use `defaults export` it reads it correctly
|
32
|
-
# as a boolean
|
33
|
-
expect( defaults.read [DOMAIN, key] ).to be(bool)
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
context "string value with @ in it" do
|
38
|
-
|
39
|
-
let(:string) {
|
40
|
-
'en_US@currency=USD'
|
41
|
-
}
|
42
|
-
|
43
|
-
before(:each) {
|
44
|
-
`defaults write #{ DOMAIN } #{ key } -string '#{ string }'`
|
45
|
-
}
|
46
|
-
|
47
|
-
it "reads a string with an @ in it" do
|
48
|
-
expect( defaults.read [DOMAIN, key] ).to eq string
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate/adapters/defaults'
|
4
|
-
|
5
|
-
describe "StateMate::Adapters::Defaults.read_type" do
|
6
|
-
include_context "defaults"
|
7
|
-
include_context "#{ DOMAIN } empty"
|
8
|
-
|
9
|
-
{
|
10
|
-
string: 'en_US@currency=USD',
|
11
|
-
data: '62706c697374',
|
12
|
-
int: '1',
|
13
|
-
float: '1',
|
14
|
-
bool: 'true',
|
15
|
-
date: '2014-03-27',
|
16
|
-
array: '1 2 3',
|
17
|
-
dict: 'x 1 y 2',
|
18
|
-
}.each do |type, input|
|
19
|
-
|
20
|
-
it "reads a #{ type } type" do
|
21
|
-
`defaults write #{ DOMAIN } x -#{ type } #{ input }`
|
22
|
-
expect( defaults.read_type DOMAIN, 'x', false ).to be type
|
23
|
-
end
|
24
|
-
|
25
|
-
it "reads a #{ type } type from current host" do
|
26
|
-
`defaults -currentHost write #{ DOMAIN } x -#{ type } #{ input }`
|
27
|
-
expect( defaults.read_type DOMAIN, 'x', true ).to be type
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'shellwords'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require 'state_mate/adapters/defaults'
|
6
|
-
|
7
|
-
describe "StateMate::Adapters::Defaults.read" do
|
8
|
-
include_context "defaults"
|
9
|
-
include_context "#{ DOMAIN } empty"
|
10
|
-
|
11
|
-
it "writes a basic value" do
|
12
|
-
defaults.write [DOMAIN, 'x'], 'ex'
|
13
|
-
expect_defaults_read 'x', eq('ex'), 'string'
|
14
|
-
end
|
15
|
-
|
16
|
-
it "writes a complex value" do
|
17
|
-
defaults.write [DOMAIN, 'one'], {'two' => 3}
|
18
|
-
expect_defaults_read 'one', struct_eq("{two=3;}"), 'dictionary'
|
19
|
-
end
|
20
|
-
|
21
|
-
it "writes a deep key" do
|
22
|
-
defaults.write [DOMAIN, 'one', 'two'], 3
|
23
|
-
expect_defaults_read 'one', struct_eq("{two=3;}"), 'dictionary'
|
24
|
-
end
|
25
|
-
|
26
|
-
context "key has string values" do
|
27
|
-
values = {'x' => 'ex', 'y' => 'why'}
|
28
|
-
|
29
|
-
before(:each) {
|
30
|
-
values.each do |key, value|
|
31
|
-
`defaults write #{ DOMAIN } #{ key } -string '#{ value }'`
|
32
|
-
end
|
33
|
-
}
|
34
|
-
|
35
|
-
it "clobbers with a deep key" do
|
36
|
-
defaults.write [DOMAIN, 'x', 'two'], 3
|
37
|
-
expect_defaults_read 'x', struct_eq("{two=3;}"), 'dictionary'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "deletes the value when nil is written to the key" do
|
41
|
-
# make sure they're there
|
42
|
-
values.each do |key, value|
|
43
|
-
expect_defaults_read key, eq(value), 'string'
|
44
|
-
end
|
45
|
-
|
46
|
-
# do the delete by writing `nil`
|
47
|
-
defaults.write [DOMAIN, 'x'], nil
|
48
|
-
|
49
|
-
# check that it's gone via the system command
|
50
|
-
expect(
|
51
|
-
`defaults read #{ DOMAIN } x 2>&1`
|
52
|
-
).to match /does\ not\ exist$/
|
53
|
-
|
54
|
-
# and check that it's gone to us
|
55
|
-
expect( defaults.read [DOMAIN, 'x'] ).to eq nil
|
56
|
-
|
57
|
-
# and check that the other one is still there
|
58
|
-
expect_defaults_read 'y', eq(values['y']), 'string'
|
59
|
-
expect( defaults.read [DOMAIN, 'y'] ).to eq values['y']
|
60
|
-
end
|
61
|
-
|
62
|
-
it "deletes the whole domain when nil is written to it with no key" do
|
63
|
-
# make sure they're there
|
64
|
-
values.each do |key, value|
|
65
|
-
expect_defaults_read key, eq(value), 'string'
|
66
|
-
end
|
67
|
-
|
68
|
-
# do the delete by writing `nil`
|
69
|
-
defaults.write [DOMAIN], nil
|
70
|
-
|
71
|
-
values.each do |key, value|
|
72
|
-
# check that it's gone via the system command
|
73
|
-
expect(
|
74
|
-
`defaults read #{ DOMAIN } #{ key } 2>&1`
|
75
|
-
).to match /does\ not\ exist$/
|
76
|
-
|
77
|
-
# and check that it's gone to us
|
78
|
-
expect( defaults.read [DOMAIN, key] ).to eq nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it "errors trying to write an empty domain or key" do
|
84
|
-
[
|
85
|
-
[DOMAIN, ''],
|
86
|
-
[''],
|
87
|
-
[],
|
88
|
-
'',
|
89
|
-
# these are actually ok, for some reason it drops trailing empty strings:
|
90
|
-
# "#{ DOMAIN }:",
|
91
|
-
# "#{ DOMAIN }::",
|
92
|
-
# but not leading ones:
|
93
|
-
":#{ DOMAIN }",
|
94
|
-
# or ones with non-empty following
|
95
|
-
"#{ DOMAIN }::x",
|
96
|
-
].each do |key|
|
97
|
-
expect {
|
98
|
-
defaults.write key, nil
|
99
|
-
}.to raise_error ArgumentError
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate/adapters/git_config'
|
4
|
-
|
5
|
-
describe "StateMate::Adapters::GitConfig.read" do
|
6
|
-
include_context "git_config"
|
7
|
-
|
8
|
-
it "reads a missing key as nil" do
|
9
|
-
expect( git_config.read key ).to eq nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should error on a bad key" do
|
13
|
-
# can't have underscore in the name
|
14
|
-
expect{ git_config.read "state_mate.test" }.to raise_error SystemCallError
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should read a present value" do
|
18
|
-
value = "blah"
|
19
|
-
`git config --global --add #{ key } #{ value }`
|
20
|
-
expect( git_config.read key ).to eq value
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate/adapters/git_config'
|
4
|
-
|
5
|
-
describe "StateMate::Adapters::GitConfig.read" do
|
6
|
-
include_context "git_config"
|
7
|
-
|
8
|
-
it "writes a value" do
|
9
|
-
value = "blah"
|
10
|
-
git_config.write key, value
|
11
|
-
expect( `git config --global --get #{ key }`.chomp ).to eq "#{ value }"
|
12
|
-
end
|
13
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require 'state_mate/adapters/json'
|
6
|
-
|
7
|
-
describe "StateMate::Adapters::JSON.read" do
|
8
|
-
include_context "json"
|
9
|
-
|
10
|
-
it "reads an empty file as nil" do
|
11
|
-
expect( json.read [@filepath] ).to be nil
|
12
|
-
end
|
13
|
-
|
14
|
-
context "file with a string value in it" do
|
15
|
-
let(:value) {
|
16
|
-
"blah"
|
17
|
-
}
|
18
|
-
|
19
|
-
before(:each) {
|
20
|
-
File.open(@filepath, 'w') {|f|
|
21
|
-
f.write JSON.dump(value)
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
it "should read the value" do
|
26
|
-
expect( json.read [@filepath] ).to eq value
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "file with a dict value in it" do
|
31
|
-
let(:value) {
|
32
|
-
{
|
33
|
-
'x' => 1,
|
34
|
-
'y' => 2,
|
35
|
-
'z' => {
|
36
|
-
'a' => 3,
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
before(:each) {
|
42
|
-
File.open(@filepath, 'w') {|f|
|
43
|
-
f.write JSON.dump(value)
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
it "should read the root value" do
|
48
|
-
expect( json.read [@filepath] ).to eq value
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should read a deeper value" do
|
52
|
-
expect( json.read "#{ @filepath }:z:a" ).to eq 3
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require 'state_mate/adapters/json'
|
6
|
-
|
7
|
-
describe "StateMate::Adapters::JSON.write" do
|
8
|
-
include_context "json"
|
9
|
-
|
10
|
-
context "root value" do
|
11
|
-
let(:value) {
|
12
|
-
{
|
13
|
-
"some_key" => "some value"
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
it "should write the value" do
|
18
|
-
json.write @filepath, value
|
19
|
-
expect( JSON.load(File.read(@filepath)) ).to eq value
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "deep value" do
|
24
|
-
let(:doc) {
|
25
|
-
{
|
26
|
-
"top-level-key" => {
|
27
|
-
'second-level-key' => "old value"
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
let(:key) {
|
33
|
-
[@filepath, "top-level-key", "second-level-key"]
|
34
|
-
}
|
35
|
-
|
36
|
-
let(:value) {
|
37
|
-
"new value"
|
38
|
-
}
|
39
|
-
|
40
|
-
before(:each) {
|
41
|
-
File.open(@filepath, 'w') do |f|
|
42
|
-
f.write JSON.dump(doc)
|
43
|
-
end
|
44
|
-
}
|
45
|
-
|
46
|
-
it "should write the value" do
|
47
|
-
json.write key, value
|
48
|
-
expect(
|
49
|
-
JSON.load(File.read(@filepath))[key[1]][key[2]]
|
50
|
-
).to eq value
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'state_mate'
|
4
|
-
|
5
|
-
describe "StateMate::execute" do
|
6
|
-
context "defaults" do
|
7
|
-
include_context "#{ DOMAIN } empty"
|
8
|
-
|
9
|
-
it "writes a basic value" do
|
10
|
-
StateMate.execute({
|
11
|
-
'defaults' => {
|
12
|
-
'key' => [DOMAIN, 'x'],
|
13
|
-
'set' => 'ex',
|
14
|
-
},
|
15
|
-
})
|
16
|
-
|
17
|
-
expect_defaults_read 'x', eq('ex'), 'string'
|
18
|
-
end
|
19
|
-
end # context defaults
|
20
|
-
|
21
|
-
context "write failure" do
|
22
|
-
include_context "#{ DOMAIN } empty"
|
23
|
-
|
24
|
-
it "raises StateMate::Error::WriteError" do
|
25
|
-
allow(StateMate::Adapters::Defaults).to receive(:write) do
|
26
|
-
raise MockError.new
|
27
|
-
end
|
28
|
-
|
29
|
-
expect {
|
30
|
-
StateMate.execute({
|
31
|
-
'defaults' => {
|
32
|
-
'key' => [DOMAIN, 'x'],
|
33
|
-
'set' => 'ex',
|
34
|
-
},
|
35
|
-
})
|
36
|
-
}.to raise_error StateMate::Error::WriteError
|
37
|
-
|
38
|
-
end # it raises StateMate::Error::WriteError
|
39
|
-
end # context write failure
|
40
|
-
end
|
data/spec/state_mate_spec.rb
DELETED
data/test/ansible/ansible.cfg
DELETED
data/test/ansible/clear
DELETED
data/test/ansible/hosts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
localhost ansible_connection=local
|
data/test/ansible/play
DELETED
data/test/ansible/playbook.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- hosts: localhost
|
3
|
-
gather_facts: false
|
4
|
-
tasks:
|
5
|
-
# - name: test defaults
|
6
|
-
# state:
|
7
|
-
# defaults:
|
8
|
-
# - key: com.nrser.state_mate:x
|
9
|
-
# set: 1
|
10
|
-
# - key: com.nrser.state_mate:blah
|
11
|
-
# set:
|
12
|
-
# blow: me
|
13
|
-
# - key: com.nrser.state_mate:key with spaces
|
14
|
-
# set: value with spaces
|
15
|
-
|
16
|
-
# - name: test launchd
|
17
|
-
# state:
|
18
|
-
# launchd:
|
19
|
-
# key:
|
20
|
-
# - /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
|
21
|
-
# - Disabled
|
22
|
-
# set: true
|
23
|
-
|
24
|
-
# - name: Disable local Time Machine snapshots
|
25
|
-
# #
|
26
|
-
# # sudo tmutil disablelocal
|
27
|
-
# #
|
28
|
-
# state:
|
29
|
-
# time_machine:
|
30
|
-
# key: local_backups
|
31
|
-
# set: false
|
32
|
-
# sudo: true
|
33
|
-
- name: test deep key
|
34
|
-
state:
|
35
|
-
defaults:
|
36
|
-
key: com.nrser.state_mate:x
|
37
|
-
set: en_US@currency=USD
|
38
|
-
|
data/test/ansible/read
DELETED
data/test/bin/install.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# build and install gem from current source
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
require 'fileutils'
|
7
|
-
require 'cmds'
|
8
|
-
|
9
|
-
sudo = Cmds("rbenv version").out.start_with?("system") ? 'sudo' : nil
|
10
|
-
|
11
|
-
ROOT = Pathname.new(__FILE__).dirname.join("..", "..").expand_path
|
12
|
-
|
13
|
-
Cmds.stream "%{sudo?} gem uninstall state_mate", sudo: sudo
|
14
|
-
|
15
|
-
Dir.chdir ROOT do
|
16
|
-
Dir["./*.gem"].each {|fn| FileUtils.rm fn}
|
17
|
-
Cmds.stream "gem build state_mate.gemspec"
|
18
|
-
end
|
19
|
-
|
20
|
-
Cmds.stream "%{sudo?} gem install %{path}",
|
21
|
-
path: Dir[ROOT + "*.gem"].first,
|
22
|
-
sudo: sudo
|