standard_path 0.1.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 (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +31 -0
  4. data/lib/standard_path.rb +171 -0
  5. metadata +49 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5ec8d3c8fcc063e727341c00c0528cff401c6f8f0c8c1b200b295a5e8144d70e
4
+ data.tar.gz: ef58cf85453846ee77ad014ec77ef2e06c4329f4557592081ab692cf1faddfc3
5
+ SHA512:
6
+ metadata.gz: c6799c4d00cc68f4cb3256cf7800b90b088051867ab1b3a41ee62ca10329f7be20cc9bf3a7292868918b9e950d62eedf0343df0d168856c2f24da1c6c7bd46ea
7
+ data.tar.gz: 2e66f7fdcf3f8abb3e66af9a46648a35489072ed075d1e9fc4d74842fe9d40ff187ed3e5359ef7b68d2980ebdb76c970cec15061c743d8617c3740aa97754acd
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Aoran Zeng. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # StandardPath
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ $ gem install standard_path
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ require 'standard_path'
13
+
14
+ StandardPath.downloads
15
+ StandardPath.music
16
+ StandardPath.app_local_data(my_app)
17
+ ```
18
+
19
+ ## APIs
20
+
21
+ - `.desktop`
22
+ - `.documents`
23
+ - `.downloads`
24
+ - `.pictures`
25
+ - `.music`
26
+ - `.videos` / `.movies`
27
+
28
+ - `.app_data(name)`
29
+ - `.app_local_data(name)`
30
+ - `.app_config(name)`
31
+ - `.app_cache(name)`
@@ -0,0 +1,171 @@
1
+ # ---------------------------------------------------------------
2
+ # File : standard_path.rb
3
+ # Authors : Aoran Zeng <ccmywish@qq.com>
4
+ # Created on : <2023-05-19>
5
+ # Last modified : <2023-05-19>
6
+ #
7
+ # stardard_path:
8
+ #
9
+ # Standard Path for corss-platform gems
10
+ # ---------------------------------------------------------------
11
+
12
+ module StandardPath
13
+
14
+ VERSION = "0.1.0"
15
+
16
+ OSes = ['Windows', 'macOS', 'Linux']
17
+
18
+ end
19
+
20
+
21
+ class << StandardPath
22
+
23
+ class UnknownOS < StandardError ; end
24
+ class NotSupportedOS < StandardError; end
25
+
26
+ def os
27
+ host_os = RbConfig::CONFIG['host_os']
28
+ if Gem.win_platform?
29
+ 'Windows'
30
+ elsif host_os =~ /darwin/
31
+ 'macOS'
32
+ elsif host_os =~ /mac/
33
+ # This condition is just for possible future compatibility only
34
+ 'macOS'
35
+ elsif host_os =~ /linux/
36
+ 'Linux'
37
+ elsif host_os =~ /freebsd/
38
+ 'FreeBSD'
39
+ raise NotSupportedOS, "Currently #{name} doesn't support FreeBSD."
40
+ else
41
+ 'Unknown'
42
+ raise UnknownOS, "#{name} doesn't know about your OS type."
43
+ end
44
+ end
45
+
46
+
47
+ def desktop(os = self.os)
48
+ case os
49
+ when 'Windows', 'macOS', 'Linux'
50
+ File.expand_path "~/Desktop"
51
+ else
52
+ raise NotSupportedOS, "#{name} doesn't know about #{__method__} path of '#{os}' you specify"
53
+ end
54
+ end
55
+
56
+
57
+ def documents(os = self.os)
58
+ case os
59
+ when 'Windows', 'macOS', 'Linux'
60
+ File.expand_path "~/Documents"
61
+ else
62
+ raise NotSupportedOS, "#{name} doesn't know about #{__method__} path of '#{os}' you specify"
63
+ end
64
+ end
65
+
66
+
67
+ def downloads(os = self.os)
68
+ case os
69
+ when 'Windows', 'macOS', 'Linux'
70
+ File.expand_path "~/Downloads"
71
+ else
72
+ raise NotSupportedOS, "#{name} doesn't know about #{__method__} path of '#{os}' you specify"
73
+ end
74
+ end
75
+
76
+
77
+ def pictures(os = self.os)
78
+ case os
79
+ when 'Windows', 'macOS', 'Linux'
80
+ File.join Dir.home, 'Pictures'
81
+ else
82
+ raise NotSupportedOS, "#{name} doesn't know about #{__method__} path of '#{os}' you specify"
83
+ end
84
+ end
85
+
86
+
87
+ def music(os = self.os)
88
+ case os
89
+ when 'Windows', 'macOS', 'Linux'
90
+ File.expand_path '~/Music'
91
+ else
92
+ raise NotSupportedOS, "#{name} doesn't know about #{__method__} path of '#{os}' you specify"
93
+ end
94
+ end
95
+
96
+
97
+ def movies(os = self.os)
98
+ case os
99
+ when 'Windows', 'Linux'
100
+ File.expand_path '~/Videos'
101
+ when 'macOS'
102
+ File.expand_path '~/Movies'
103
+ else
104
+ raise NotSupportedOS, "#{name} doesn't know about #{__method__} path of '#{os}' you specify"
105
+ end
106
+ end
107
+
108
+
109
+ alias videos movies
110
+
111
+
112
+ def app_data(app, os = self.os)
113
+ base = case os
114
+ when 'Windows'
115
+ File.join "~/AppData/Roaming", app
116
+ when 'macOS'
117
+ File.join "~/Library/Application Support", app
118
+ when 'Linux'
119
+ File.join "~/.local/share", app
120
+ else
121
+ raise NotSupportedOS, "#{self.name} doesn't know about #{__method__} path of '#{os}' you specify"
122
+ end
123
+ File.expand_path base
124
+ end
125
+
126
+
127
+ def app_local_data(app, os = self.os)
128
+ base = case os
129
+ when 'Windows'
130
+ File.join "~/AppData/Local", app
131
+ when 'macOS'
132
+ File.join "~/Library/Application Support", app
133
+ when 'Linux'
134
+ File.join "~/.local/share", app
135
+ else
136
+ raise NotSupportedOS, "#{self.name} doesn't know about #{__method__} path of '#{os}' you specify"
137
+ end
138
+ File.expand_path base
139
+ end
140
+
141
+
142
+ def app_config(app, os = self.os)
143
+ base = case os
144
+ when 'Windows'
145
+ File.join "~/AppData/Local", app
146
+ when 'macOS'
147
+ File.join "~/Library/Preferences", app
148
+ when 'Linux'
149
+ File.join '~/.config', app
150
+ else
151
+ raise NotSupportedOS, "#{self.name} doesn't know about #{__method__} path of '#{os}' you specify"
152
+ end
153
+ File.expand_path base
154
+ end
155
+
156
+
157
+ def app_cache(app, os = self.os)
158
+ base = case os
159
+ when 'Windows'
160
+ File.join "~/AppData/Local", app, 'cache'
161
+ when 'macOS'
162
+ File.join "~/Library/Caches", app
163
+ when 'Linux'
164
+ File.join '~/.cache', app
165
+ else
166
+ raise NotSupportedOS, "#{self.name} doesn't know about #{__method__} path of '#{os}' you specify"
167
+ end
168
+ File.expand_path base
169
+ end
170
+
171
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: standard_path
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aoran Zeng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Standard Path for corss-platform gems.
14
+
15
+ '
16
+ email: ccmywish@qq.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE.txt
22
+ - README.md
23
+ - lib/standard_path.rb
24
+ homepage: https://github.com/ccmywish/standard_path
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ bug_tracker_uri: https://github.com/ccmywish/standard_path/issues
29
+ source_code_uri: https://github.com/ccmywish/standard_path
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 2.7.0
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.4.8
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Standard Path for corss-platform gems
49
+ test_files: []