macos.rb 0.50.0

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 (70) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +572 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +21 -0
  5. data/README.md +129 -0
  6. data/Rakefile +9 -0
  7. data/lib/Array/all_but_last.rb +7 -0
  8. data/lib/MacOS/Apple80211.rb +68 -0
  9. data/lib/MacOS/Applications.rb +73 -0
  10. data/lib/MacOS/Defaults/ComAppleDock.rb +153 -0
  11. data/lib/MacOS/Defaults/NSGlobalDomain/NSUserKeyEquivalents.rb +109 -0
  12. data/lib/MacOS/Defaults.rb +126 -0
  13. data/lib/MacOS/DiskUtil.rb +63 -0
  14. data/lib/MacOS/Dmg.rb +99 -0
  15. data/lib/MacOS/HardwarePort.rb +79 -0
  16. data/lib/MacOS/IfConfig.rb +183 -0
  17. data/lib/MacOS/Keychain.rb +26 -0
  18. data/lib/MacOS/LaunchControl.rb +36 -0
  19. data/lib/MacOS/SystemProfiler.rb +119 -0
  20. data/lib/MacOS/USBFlashDrive.rb +26 -0
  21. data/lib/MacOS/Users.rb +16 -0
  22. data/lib/MacOS/VERSION.rb +6 -0
  23. data/lib/MacOS/VPN.rb +13 -0
  24. data/lib/MacOS/Voice.rb +40 -0
  25. data/lib/MacOS.rb +27 -0
  26. data/lib/Module/alias_methods.rb +7 -0
  27. data/lib/Ordinal/Array.rb +8 -0
  28. data/lib/Ordinal.rb +157 -0
  29. data/lib/Thoran/Array/AllButLast/all_but_last.rb +28 -0
  30. data/lib/Thoran/Array/LastX/lastX.rb +33 -0
  31. data/lib/Thoran/Module/AliasMethods/alias_methods.rb +23 -0
  32. data/lib/Thoran/String/Capture/capture.rb +28 -0
  33. data/lib/Version.rb +381 -0
  34. data/macos.rb.gemspec +59 -0
  35. data/test/MacOS/Apple80211_test.rb +80 -0
  36. data/test/MacOS/Applications_test.rb +82 -0
  37. data/test/MacOS/Defaults/ComAppleDock_test.rb +66 -0
  38. data/test/MacOS/Defaults/NSGlobalDomain/NSUserKeyEquivalents_test.rb +67 -0
  39. data/test/MacOS/Defaults_test.rb +144 -0
  40. data/test/MacOS/DiskUtil_test.rb +48 -0
  41. data/test/MacOS/Dmg_test.rb +69 -0
  42. data/test/MacOS/HardwarePort_test.rb +46 -0
  43. data/test/MacOS/IfConfig_test.rb +144 -0
  44. data/test/MacOS/Keychain_test.rb +22 -0
  45. data/test/MacOS/LaunchControl_test.rb +40 -0
  46. data/test/MacOS/SystemProfiler_test.rb +69 -0
  47. data/test/MacOS/USBFlashDrive_test.rb +20 -0
  48. data/test/MacOS/Users_test.rb +10 -0
  49. data/test/MacOS/VPN_test.rb +18 -0
  50. data/test/MacOS/Voice_test.rb +46 -0
  51. data/test/MacOS_test.rb +17 -0
  52. data/test/VERSION_test.rb +19 -0
  53. data/test/commands_test.rb +50 -0
  54. data/test/fixtures/airport-I-deprecated.txt +2 -0
  55. data/test/fixtures/airport-I.txt +17 -0
  56. data/test/fixtures/defaults-domains.txt +1 -0
  57. data/test/fixtures/defaults-export-com.apple.dock.xml +47 -0
  58. data/test/fixtures/defaults-read-NSUserKeyEquivalents.txt +4 -0
  59. data/test/fixtures/df-k.txt +6 -0
  60. data/test/fixtures/diskutil-list-plist.xml +104 -0
  61. data/test/fixtures/dscl-list-users.txt +8 -0
  62. data/test/fixtures/ifconfig-a.txt +53 -0
  63. data/test/fixtures/networksetup-listallhardwareports.txt +39 -0
  64. data/test/fixtures/say-v.txt +8 -0
  65. data/test/fixtures/system_profiler-SPAirPortDataType.txt +44 -0
  66. data/test/fixtures/system_profiler-SPSoftwareDataType.txt +14 -0
  67. data/test/fixtures/system_profiler-SPUSBDataType.txt +58 -0
  68. data/test/gemspec_test.rb +50 -0
  69. data/test/helper.rb +18 -0
  70. metadata +183 -0
@@ -0,0 +1,40 @@
1
+ # MacOS/Voice.rb
2
+ # MacOS::Voice
3
+
4
+ # Notes:
5
+ # 1. Taken from Kernel/say.rb 0.4.2.
6
+
7
+ module MacOS
8
+ class Voice
9
+ attr_reader :name, :localization, :description
10
+
11
+ class << self
12
+
13
+ def all
14
+ `say -v '?'`.lines.collect{|line| new_from_line(line)}
15
+ end
16
+ alias_method :list, :all
17
+
18
+ def random_voice
19
+ list.sample
20
+ end
21
+
22
+ private
23
+
24
+ def new_from_line(line)
25
+ name_and_localization, description = line.split('#', 2)
26
+ description = description.strip
27
+ *name, localization = name_and_localization.split
28
+ Voice.new(name: name.join(' '), localization: localization, description: description)
29
+ end
30
+
31
+ end # class << self
32
+
33
+ def initialize(name:, localization:, description:)
34
+ @name = name
35
+ @localization = localization
36
+ @description = description
37
+ end
38
+
39
+ end
40
+ end
data/lib/MacOS.rb ADDED
@@ -0,0 +1,27 @@
1
+ # MacOS.rb
2
+
3
+ require 'MacOS/Apple80211'
4
+ require 'MacOS/Applications'
5
+ require 'MacOS/Defaults'
6
+ require 'MacOS/Defaults/ComAppleDock'
7
+ require 'MacOS/Defaults/NSGlobalDomain/NSUserKeyEquivalents'
8
+ require 'MacOS/DiskUtil'
9
+ require 'MacOS/Dmg'
10
+ require 'MacOS/HardwarePort'
11
+ require 'MacOS/IfConfig'
12
+ require 'MacOS/Keychain'
13
+ require 'MacOS/LaunchControl'
14
+ require 'MacOS/SystemProfiler'
15
+ require 'MacOS/USBFlashDrive'
16
+ require 'MacOS/Users'
17
+ require 'MacOS/VERSION'
18
+ require 'MacOS/VPN'
19
+ require 'MacOS/Voice'
20
+
21
+ module MacOS
22
+ module_function
23
+
24
+ def version
25
+ MacOS::SystemProfiler.system_version
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ # Module/alias_methods.rb
2
+ # Module#alias_methods
3
+
4
+ # 20180806
5
+ # 0.1.0 (The same version number as the current version of Thoran/Module/AliasMethods.)
6
+
7
+ require 'Thoran/Module/AliasMethods/alias_methods'
@@ -0,0 +1,8 @@
1
+ # Ordinal/Array.rb
2
+ # Ordinal/Array
3
+
4
+ require_relative '../Ordinal'
5
+
6
+ class Array
7
+ include Ordinal
8
+ end
data/lib/Ordinal.rb ADDED
@@ -0,0 +1,157 @@
1
+ # Ordinal.rb
2
+ # Ordinal
3
+
4
+ # 20220527
5
+ # 0.2.1
6
+
7
+ # Description: This is a collection of methods which relies upon an object having an entries method.
8
+
9
+ # Notes:
10
+ # 1. This was originally meant to be extensions on Enumerable, as can be seen in version 0.0.0, but I decided that any object which provides for an ordered list of entries by way of having an entries method should be able to make use of this.
11
+
12
+ # Changes since 0.1:
13
+ # 1. - require 'File/self.relative_path' from Ordinal/Array and replaced with require_relative.
14
+ # 2. - require 'File/self.relative_path' from Ordinal/Array and replaced with require_relative.
15
+ # 0/1
16
+ # 3. /ninteenth/nineteenth/
17
+
18
+ module Ordinal
19
+
20
+ def first
21
+ entries[0]
22
+ end
23
+
24
+ def second
25
+ entries[1]
26
+ end
27
+
28
+ def third
29
+ entries[2]
30
+ end
31
+
32
+ def fourth
33
+ entries[3]
34
+ end
35
+
36
+ def fifth
37
+ entries[4]
38
+ end
39
+
40
+ def sixth
41
+ entries[5]
42
+ end
43
+
44
+ def seventh
45
+ entries[6]
46
+ end
47
+
48
+ def eighth
49
+ entries[7]
50
+ end
51
+
52
+ def ninth
53
+ entries[8]
54
+ end
55
+
56
+ def tenth
57
+ entries[9]
58
+ end
59
+
60
+ def eleventh
61
+ entries[10]
62
+ end
63
+
64
+ def twelfth
65
+ entries[11]
66
+ end
67
+
68
+ def thirteenth
69
+ entries[12]
70
+ end
71
+
72
+ def fourteenth
73
+ entries[13]
74
+ end
75
+
76
+ def fifteenth
77
+ entries[14]
78
+ end
79
+
80
+ def sixteenth
81
+ entries[15]
82
+ end
83
+
84
+ def seventeenth
85
+ entries[16]
86
+ end
87
+
88
+ def eighteenth
89
+ entries[17]
90
+ end
91
+
92
+ def nineteenth
93
+ entries[18]
94
+ end
95
+
96
+ def twentieth
97
+ entries[19]
98
+ end
99
+
100
+ def tenth_last
101
+ entries[count - 10]
102
+ end
103
+
104
+ def ninth_last
105
+ entries[count - 9]
106
+ end
107
+
108
+ def eighth_last
109
+ entries[count - 8]
110
+ end
111
+
112
+ def seventh_last
113
+ entries[count - 7]
114
+ end
115
+
116
+ def sixth_last
117
+ entries[count - 6]
118
+ end
119
+
120
+ def fifth_last
121
+ entries[count - 5]
122
+ end
123
+
124
+ def fourth_last
125
+ entries[count - 4]
126
+ end
127
+
128
+ def third_last
129
+ entries[count - 3]
130
+ end
131
+
132
+ def second_last
133
+ entries[count - 2]
134
+ end
135
+
136
+ def last
137
+ entries[count - 1]
138
+ end
139
+ alias_method :first_last, :last
140
+
141
+ def all_but_first
142
+ entries.drop(1)
143
+ end
144
+
145
+ def all_but_last
146
+ entries.take(count - 1)
147
+ end
148
+
149
+ def all_but_first_and_last
150
+ entries.all_but_first.all_but_last
151
+ end
152
+
153
+ def first_and_last
154
+ [entries.first] + [entries.last]
155
+ end
156
+
157
+ end
@@ -0,0 +1,28 @@
1
+ # Thoran/Array/AllButLast/all_but_last.rb
2
+ # Thoran::Array::AllButLast#all_but_last
3
+
4
+ # 20180804
5
+ # 0.1.0
6
+
7
+ # Description: This returns a copy of the receiving array with the last element removed.
8
+
9
+ # Changes:
10
+ # 1. + Thoran namespace.
11
+
12
+ require 'Thoran/Array/LastX/lastX'
13
+
14
+ module Thoran
15
+ module Array
16
+ module AllButLast
17
+
18
+ def all_but_last
19
+ d = self.dup
20
+ d.last!
21
+ d
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
28
+ Array.send(:include, Thoran::Array::AllButLast)
@@ -0,0 +1,33 @@
1
+ # Thoran/Array/LastX/lastX.rb
2
+ # Thoran::Array::LastX#last!
3
+
4
+ # 20180804
5
+ # 0.2.3
6
+
7
+ # Description: Sometimes it makes more sense to treat arrays this way.
8
+
9
+ # Changes since 0.1:
10
+ # 1. Added the complement of the extended version of Array#first!.
11
+ # 0/1
12
+ # 2. Switched the tests to spec-style.
13
+ # 1/2
14
+ # 3. Added a test for the state of the array afterward, since this is meant to be an in place change.
15
+ # 2/3
16
+ # 4. Added tests for the extended functionality introduced in the first version 0.1.0.
17
+ # 5. Fixed the implementation, so that the order is retained by unshifting the popped values rather than appending the shifted values as is the case with Array#first!.
18
+
19
+ module Thoran
20
+ module Array
21
+ module LastX
22
+
23
+ def last!(n = 1)
24
+ return_value = []
25
+ n.times{return_value.unshift(self.pop)}
26
+ return_value.size == 1 ? return_value[0] : return_value
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
33
+ Array.send(:include, Thoran::Array::LastX)
@@ -0,0 +1,23 @@
1
+ # Thoran/Module/AliasMethods/alias_methods.rb
2
+ # Thoran::Module::AliasMethods#alias_methods
3
+
4
+ # 20180806
5
+ # 0.1.0
6
+
7
+ # Description: I have a penchance for having multiple method names and having line after line of alias_method calls is kinda ugly.
8
+
9
+ require 'Array/all_but_last'
10
+
11
+ module Thoran
12
+ module Module
13
+ module AliasMethods
14
+
15
+ def alias_methods(*args)
16
+ args.all_but_last.each{|e| alias_method e.to_sym, args.last.to_sym}
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ Module.send(:include, Thoran::Module::AliasMethods)
@@ -0,0 +1,28 @@
1
+ # Thoran/String/Capture/capture.rb
2
+ # Thoran::String::Capture#capture
3
+
4
+ # 20161109
5
+ # 0.3.1
6
+
7
+ # Changes since 0.2:
8
+ # 1. + Thoran namespace.
9
+ # 0/1
10
+ # 2. Updated the MiniTest superclass only---no implementation changes.
11
+
12
+ module Thoran
13
+ module String
14
+ module Capture
15
+
16
+ def capture(regex)
17
+ if md = self.match(regex)
18
+ md[1]
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
28
+ String.send(:include, Thoran::String::Capture)