state_mate 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48fd4c0c71a34bcd84727dca505091aebfa44981
4
- data.tar.gz: 2e6cab4f5cd7c579b238175d498cec2a7801d268
3
+ metadata.gz: 5aba1e0cd11231bc25d168f117aab8cf89056f3b
4
+ data.tar.gz: 3c1bb3640ca889f7a5b19ed4530b2093dec734d5
5
5
  SHA512:
6
- metadata.gz: 60f3b23aac04175f0cae6ddc32fbae4ab32ae5d58fe36a6a7de5da733202ef7d3792e4ba540dea3f66b4b1cb1c1d9ccd190f2ec434848270b95c30302d6114bd
7
- data.tar.gz: a44733da28c6f8ba4542142be71673af07b2c7e35dc89cf14994421b5abf61624efb2d33fc9acf705dbc4cf5479dd7fbd9b3e10730433b55237f35491dbf0be7
6
+ metadata.gz: e4c92a705ec2c6e6c62a887d0b0023ea69cdff660d01fde5ffbbcae8eaed2fc88d878b3f21686437ff07814beb5b99564a2dbcb74fe289920c93d31e3dceef90
7
+ data.tar.gz: 2bf7d8f08317ca320acc21296791e8b3f92d165faf9c0161354c7cec8c9576d8896bf4eba7d6ff0c28af32f7ced6e1d180acd6906b0e07bc557e9f0763493b73
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # use local
4
- # gem 'nrser', '~> 0.0', :path => '../nrser-ruby'
4
+ # gem 'nrser', '0.0.13.dev', :path => '../nrser-ruby'
5
5
 
6
6
  # Specify your gem's dependencies in state_mate.gemspec
7
7
  gemspec
@@ -515,12 +515,15 @@ module StateMate::Adapters::Defaults
515
515
  #
516
516
  # @return nil
517
517
  #
518
- def self.basic_delete domain, key, current_host
519
- Cmds! '%{cmd} %{current_host?} delete %{domain} %{key?}',
518
+ def self.basic_delete domain, key, current_host
519
+ sudo = domain.start_with?('/Library') ? "sudo" : nil
520
+
521
+ Cmds! '%{sudo?} %{cmd} %{current_host?} delete %{domain} %{key?}',
520
522
  cmd: DEFAULTS_CMD,
521
523
  current_host: (current_host ? '-currentHost' : nil),
522
524
  domain: domain,
523
- key: (key ? key : nil)
525
+ key: (key ? key : nil),
526
+ sudo: sudo
524
527
 
525
528
  nil
526
529
  end
@@ -549,12 +552,15 @@ module StateMate::Adapters::Defaults
549
552
  if value.nil?
550
553
  basic_delete(domain, key, current_host)
551
554
  else
552
- Cmds! '%{cmd} %{current_host?} write %{domain} %{key?} %{xml}',
555
+ sudo = domain.start_with?('/Library') ? "sudo" : nil
556
+
557
+ Cmds! '%{sudo?} %{cmd} %{current_host?} write %{domain} %{key?} %{xml}',
553
558
  cmd: DEFAULTS_CMD,
554
559
  current_host: (current_host ? '-currentHost' : nil),
555
560
  domain: domain,
556
561
  key: (key ? key : nil),
557
- xml: to_xml_element(value).to_s
562
+ xml: to_xml_element(value).to_s,
563
+ sudo: sudo
558
564
  end
559
565
 
560
566
  nil
@@ -3,7 +3,6 @@ require 'pp'
3
3
  require 'CFPropertyList'
4
4
 
5
5
  require 'nrser'
6
- require 'nrser/exec'
7
6
 
8
7
  require 'state_mate'
9
8
  require 'state_mate/adapters/defaults'
@@ -36,7 +35,7 @@ module StateMate::Adapters::LaunchD
36
35
  if user == 'root'
37
36
  "/var/db/launchd.db/com.apple.launchd/overrides.plist"
38
37
  else
39
- user_id = NRSER::Exec.run("id -u %{user}", user: user).chomp.to_i
38
+ user_id = Cmds!("id -u %{user}", user: user).out.chomp.to_i
40
39
  "/var/db/launchd.db/com.apple.launchd.peruser.#{ user_id }/overrides.plist"
41
40
  end
42
41
  end
@@ -53,13 +52,7 @@ module StateMate::Adapters::LaunchD
53
52
  end
54
53
 
55
54
  def self.loaded? label
56
- begin
57
- NRSER::Exec.run "%{exe} list -x %{label}", exe: EXE, label: label
58
- rescue SystemCallError => e
59
- false
60
- else
61
- true
62
- end
55
+ Cmds.ok? "%{exe} list -x %{label}", exe: EXE, label: label
63
56
  end
64
57
 
65
58
  def self.parse_key key
@@ -68,13 +61,13 @@ module StateMate::Adapters::LaunchD
68
61
  end
69
62
 
70
63
  def self.load file_path
71
- NRSER::Exec.run "%{exe} load -w %{file_path}", exe: EXE,
72
- file_path: file_path
64
+ Cmds! "%{exe} load -w %{file_path}", exe: EXE,
65
+ file_path: file_path
73
66
  end
74
67
 
75
68
  def self.unload file_path
76
- NRSER::Exec.run "%{exe} unload -w %{file_path}", exe: EXE,
77
- file_path: file_path
69
+ Cmds! "%{exe} unload -w %{file_path}", exe: EXE,
70
+ file_path: file_path
78
71
  end
79
72
 
80
73
  def self.read key, options = {}
@@ -114,4 +107,4 @@ module StateMate::Adapters::LaunchD
114
107
  raise "unprocessable key: #{ key.inspect }"
115
108
  end
116
109
  end
117
- end # LaunchD
110
+ end # LaunchD
@@ -1,3 +1,3 @@
1
1
  module StateMate
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/state_mate.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'set'
2
2
  require 'nrser'
3
+ require 'nrser/refinements'
4
+
5
+ using NRSER
3
6
 
4
7
  require "state_mate/version"
5
8
 
@@ -164,7 +167,7 @@ module StateMate
164
167
  state.options
165
168
  rescue Exception => e
166
169
  @new_value_error = e
167
- raise Error::ValueChangeError.new tpl binding, <<-BLOCK
170
+ raise Error::ValueChangeError.new binding.erb <<-BLOCK
168
171
  an error occured when changing a values:
169
172
 
170
173
  <%= @new_value_error.format %>
@@ -184,7 +187,7 @@ module StateMate
184
187
  rescue Exception => e
185
188
  @write_error = e
186
189
  rollback
187
- raise Error::WriteError.new tpl binding, <<-BLOCK
190
+ raise Error::WriteError.new binding.erb <<-BLOCK
188
191
  an error occured when writing new state values:
189
192
 
190
193
  <%= @write_error.format %>
@@ -250,8 +253,8 @@ module StateMate
250
253
  StateMate::Adapters.constants.find {|sym|
251
254
  sym.to_s.downcase == adapter_name.gsub('_', '')
252
255
  }.pipe {|sym| StateMate::Adapters.const_get sym}
253
- rescue
254
- raise "can't find adapter #{ adapter_name.inspect }"
256
+ rescue Exception => e
257
+ raise "can't find adapter #{ adapter_name.inspect }: #{ e }"
255
258
  end
256
259
  end
257
260
 
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,8 @@ require 'state_mate'
5
5
 
6
6
  DOMAIN = 'com.nrser.state_mate'
7
7
 
8
+ class MockError < StandardError; end
9
+
8
10
  shared_context "#{ DOMAIN } empty" do
9
11
  before(:each) {
10
12
  `defaults delete #{ DOMAIN } 2>&1 > /dev/null`
@@ -0,0 +1,40 @@
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/state_mate.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "yard"
24
24
  spec.add_development_dependency "redcarpet"
25
25
 
26
- spec.add_dependency 'nrser', '~> 0.0.12'
26
+ spec.add_dependency 'nrser', '>= 0.0.13'
27
27
  spec.add_dependency 'CFPropertyList', '~> 2.3'
28
- spec.add_dependency 'cmds', '~> 0.0.6'
28
+ spec.add_dependency 'cmds', '>= 0.0.7'
29
29
  end
@@ -0,0 +1,22 @@
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_mate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
@@ -14,114 +14,114 @@ dependencies:
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: redcarpet
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: nrser
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.0.12
89
+ version: 0.0.13
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 0.0.12
96
+ version: 0.0.13
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: CFPropertyList
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '2.3'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.3'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: cmds
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.0.6
117
+ version: 0.0.7
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 0.0.6
124
+ version: 0.0.7
125
125
  description:
126
126
  email:
127
127
  - neil@ztkae.com
@@ -129,10 +129,9 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
- - .gitignore
133
- - .rspec
134
- - .ruby-version
135
- - .yardopts
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".yardopts"
136
135
  - Gemfile
137
136
  - LICENSE.txt
138
137
  - README.md
@@ -158,6 +157,7 @@ files:
158
157
  - spec/state_mate/adapters/git_config/write_spec.rb
159
158
  - spec/state_mate/adapters/json/read_spec.rb
160
159
  - spec/state_mate/adapters/json/write_spec.rb
160
+ - spec/state_mate/execute_spec.rb
161
161
  - spec/state_mate_spec.rb
162
162
  - state_mate.gemspec
163
163
  - test/ansible/ansible.cfg
@@ -166,6 +166,7 @@ files:
166
166
  - test/ansible/play
167
167
  - test/ansible/playbook.yml
168
168
  - test/ansible/read
169
+ - test/bin/install.rb
169
170
  homepage: https://github.com/nrser/state_mate
170
171
  licenses:
171
172
  - MIT
@@ -176,17 +177,17 @@ require_paths:
176
177
  - lib
177
178
  required_ruby_version: !ruby/object:Gem::Requirement
178
179
  requirements:
179
- - - '>='
180
+ - - ">="
180
181
  - !ruby/object:Gem::Version
181
182
  version: '0'
182
183
  required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  requirements:
184
- - - '>='
185
+ - - ">="
185
186
  - !ruby/object:Gem::Version
186
187
  version: '0'
187
188
  requirements: []
188
189
  rubyforge_project:
189
- rubygems_version: 2.0.14
190
+ rubygems_version: 2.2.2
190
191
  signing_key:
191
192
  specification_version: 4
192
193
  summary: i heard it's meant to help you with your state, mate!
@@ -202,6 +203,7 @@ test_files:
202
203
  - spec/state_mate/adapters/git_config/write_spec.rb
203
204
  - spec/state_mate/adapters/json/read_spec.rb
204
205
  - spec/state_mate/adapters/json/write_spec.rb
206
+ - spec/state_mate/execute_spec.rb
205
207
  - spec/state_mate_spec.rb
206
208
  - test/ansible/ansible.cfg
207
209
  - test/ansible/clear
@@ -209,4 +211,5 @@ test_files:
209
211
  - test/ansible/play
210
212
  - test/ansible/playbook.yml
211
213
  - test/ansible/read
214
+ - test/bin/install.rb
212
215
  has_rdoc:
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- system