etcetera 0.12.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.
data/lib/etcetera.rb ADDED
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "etcetera/version"
4
+ require_relative "etcetera/base_strategy"
5
+ require_relative "etcetera/base_strategy/apple"
6
+ require_relative "etcetera/base_strategy/windows"
7
+ require_relative "etcetera/base_strategy/xdg"
8
+ require_relative "etcetera/app_strategy"
9
+ require_relative "etcetera/app_strategy/apple"
10
+ require_relative "etcetera/app_strategy/unix"
11
+ require_relative "etcetera/app_strategy/windows"
12
+ require_relative "etcetera/app_strategy/xdg"
13
+
14
+ # This is a Ruby library that allows you to determine the locations of configuration, data, cache & other files for your application.
15
+ # Existing Ruby libraries generally do not give you a choice in terms of which standards/conventions they follow.
16
+ # Etcetera, on the other hand, gives you the choice.
17
+ #
18
+ # = Conventions
19
+ # Etcetera supports the following conventions:
20
+ # - the {XDG base directory}[https://standards.freedesktop.org/basedir/latest/]
21
+ # - Apple’s {Standard Directories}[https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html]
22
+ # - Window’s {Known Folder Locations}[https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid]
23
+ # - the "Unix Single-folder Convention" i.e. everything in <tt>~/.myapp</tt>
24
+ #
25
+ # = Strategies
26
+ # If you want to get started quickly, you can use the following convenience functions that use the default strategies (as determined arbitrarily by yours truly) or the native strategies for each OS.
27
+ #
28
+ # == BaseStrategy
29
+ # If you just want to get the path to a configuration, data, cache or another directory, you can use the +choose_base_strategy+ function.
30
+ #
31
+ # require "etcetera"
32
+ #
33
+ # strategy = Etcetera.choose_base_strategy
34
+ #
35
+ # config_dir = strategy.config_dir
36
+ # data_dir = strategy.data_dir
37
+ # cache_dir = strategy.cache_dir
38
+ # state_dir = strategy.state_dir
39
+ # runtime_dir = strategy.runtime_dir
40
+ #
41
+ # == AppStrategy
42
+ # If you want to get the path to a configuration, data, cache or another directory, and you want to follow the naming conventions for your application, you can use the +choose_app_strategy+ function.
43
+ #
44
+ # Let’s take an application created by <tt>Acme Corp</tt> with the name <tt>Frobnicator Plus</tt> and the top-level domain of <tt>org</tt> as an example.
45
+ # - XDG strategy would place these in <tt>~/.config/frobnicator-plus</tt>.
46
+ # - Unix strategy would place these in <tt>~/.frobnicator-plus</tt>.
47
+ # - Apple strategy would place these in <tt>~/Library/Preferences/org.acme-corp.Frobnicator-Plus</tt>.
48
+ # - Windows strategy would place these in <tt>~\AppData\Roaming\Acme Corp\Frobnicator Plus</tt>.
49
+ #
50
+ # require "etcetera"
51
+ #
52
+ # strategy = Etcetera.choose_app_strategy(Etcetera::AppStrategyArgs.new(
53
+ # top_level_domain: "org",
54
+ # author: "Acme Corp",
55
+ # app_name: "Frobnicator Plus"
56
+ # ))
57
+ #
58
+ # config_dir = strategy.config_dir
59
+ # data_dir = strategy.data_dir
60
+ # cache_dir = strategy.cache_dir
61
+ # state_dir = strategy.state_dir
62
+ # runtime_dir = strategy.runtime_dir
63
+ #
64
+ # == Native Strategy
65
+ #
66
+ # +choose_base_strategy+ and +choose_app_strategy+ will use the +XDG+ strategy on Linux & macOS, and the +Windows+ strategy on \Windows.
67
+ # This is used by most CLI tools & some GUI tools on each platform.
68
+ #
69
+ # If you're developing a GUI application, you might want to use the "Standard directories" on macOS by using +choose_native_strategy+ instead.
70
+ # Note that if your application expects the user to modify the configuration files, you should still prefer the +XDG+ strategy on macOS.
71
+ #
72
+ # == Custom Conventions
73
+ #
74
+ # You aren’t limited to the built-in conventions – you can implement the relevant modules yourself. Please consider contributing these back, as the more preset conventions there are, the better.
75
+ #
76
+ # = More Examples
77
+ # Say you were a hardened Unix veteran, and didn’t want to have any of this XDG nonsense, clutter in the home directory be damned! Instead of using +choose_app_strategy+ or +choose_base_strategy+, you can pick a strategy yourself. Here’s an example using the AppStrategy::Unix strategy – see its documentation to see what kind of folder structures it produces:
78
+ #
79
+ # require "etcetera"
80
+ #
81
+ # strategy = Etcetera::AppStrategy::Unix.new(Etcetera::AppStrategyArgs.new(
82
+ # top_level_domain: "com",
83
+ # author: "Hardened Unix Veteran Who Likes Short Command Names",
84
+ # app_name: "wry"
85
+ # ))
86
+ #
87
+ # config_dir = strategy.config_dir # produces ~/.wry/
88
+ # # et cetera.
89
+ #
90
+ # Oftentimes the location of a configuration, data or cache directory is needed solely to create a path that starts inside it. For this purpose, AppStrategy implements a couple of convenience methods for you:
91
+ #
92
+ # require "etcetera"
93
+ #
94
+ # strategy = Etcetera.choose_app_strategy(Etcetera::AppStrategyArgs.new(
95
+ # top_level_domain: "org",
96
+ # author: "Acme Corp",
97
+ # app_name: "Frobnicator"
98
+ # ))
99
+ #
100
+ # # Path to configuration directory.
101
+ # config_dir = strategy.config_dir
102
+ #
103
+ # # Path to config.toml inside the configuration directory.
104
+ # config_file = strategy.in_config_dir("config.toml")
105
+ #
106
+ # config_dir.join("config.toml") == config_file # => true
107
+ module Etcetera
108
+ AppStrategyArgs = AppStrategy::AppStrategyArgs
109
+
110
+ # A convenience function that wraps the {home}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-home] function from the standard library.
111
+ def self.home_dir
112
+ Pathname.new(Dir.home)
113
+ rescue ArgumentError
114
+ raise HomeDirError
115
+ end
116
+
117
+ # This error occurs when the home directory cannot be located.
118
+ class HomeDirError < StandardError
119
+ def initialize(message = "could not locate home directory")
120
+ super
121
+ end
122
+ end
123
+
124
+ # Returns the current OS’s default BaseStrategy.
125
+ # This uses the BaseStrategy::Windows strategy on \Windows, and BaseStrategy::Xdg everywhere else.
126
+ # This is the convention used by most CLI applications.
127
+ def self.choose_base_strategy = BaseStrategy.choose_base_strategy
128
+
129
+ # Returns the current OS’s default AppStrategy.
130
+ # This uses the AppStrategy::Windows strategy on \Windows, and AppStrategy::Xdg everywhere else.
131
+ # This is the convention used by most CLI applications.
132
+ def self.choose_app_strategy(args) = AppStrategy.choose_app_strategy(args)
133
+ end
@@ -0,0 +1,15 @@
1
+ module Etcetera
2
+ module AppStrategy
3
+ class Apple < Data
4
+ include AppStrategy
5
+ include _AppStrategy
6
+
7
+ def self.new: (AppStrategyArgs args) -> instance
8
+
9
+ private
10
+
11
+ attr_reader base_strategy: BaseStrategy::Apple
12
+ attr_reader bundle_id: String
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Etcetera
2
+ module AppStrategy
3
+ class Unix < Data
4
+ include AppStrategy
5
+ include _AppStrategy
6
+
7
+ def self.new: (AppStrategyArgs args) -> instance
8
+
9
+ private
10
+
11
+ attr_reader unixy_name: String
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Etcetera
2
+ module AppStrategy
3
+ class Windows < Data
4
+ include AppStrategy
5
+ include _AppStrategy
6
+
7
+ def self.new: (AppStrategyArgs args) -> instance
8
+
9
+ private
10
+
11
+ attr_reader base_strategy: BaseStrategy::Windows
12
+ attr_reader author_app_name_path: Pathname
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Etcetera
2
+ module AppStrategy
3
+ class Xdg < Data
4
+ include AppStrategy
5
+ include _AppStrategy
6
+
7
+ def self.new: (AppStrategyArgs args) -> instance
8
+
9
+ private
10
+
11
+ attr_reader base_strategy: BaseStrategy::Xdg
12
+ attr_reader unixy_name: String
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ module Etcetera
2
+ # Allows applications to retrieve the paths of configuration, data, and cache directories specifically for them.
3
+ interface _AppStrategy
4
+ def home_dir: () -> Pathname
5
+ def config_dir: () -> Pathname
6
+ def data_dir: () -> Pathname
7
+ def cache_dir: () -> Pathname
8
+ def state_dir: () -> Pathname?
9
+ def runtime_dir: () -> Pathname?
10
+ end
11
+
12
+ # These strategies require you to provide some information on your application, and they will in turn locate the configuration/data/cache directory specifically for your application.
13
+ module AppStrategy : _AppStrategy
14
+ # The arguments to the creator method of an AppStrategy.
15
+ class AppStrategyArgs < Data
16
+ attr_reader top_level_domain: String
17
+ attr_reader author: String
18
+ attr_reader app_name: String
19
+
20
+ def self.new: (?top_level_domain: String, ?author: String, ?app_name: String) -> instance
21
+ def initialize: (?top_level_domain: String, ?author: String, ?app_name: String) -> void
22
+
23
+ def bundle_id: () -> String
24
+ def unixy_name: () -> String
25
+ end
26
+
27
+ def self.choose_native_strategy: (AppStrategyArgs args) -> native_app_strategy
28
+ def self.choose_app_strategy: (AppStrategyArgs args) -> default_app_strategy
29
+
30
+ def in_config_dir: (Pathname | String path) -> Pathname
31
+ def in_data_dir: (Pathname | String path) -> Pathname
32
+ def in_cache_dir: (Pathname | String path) -> Pathname
33
+ def in_state_dir: (Pathname | String path) -> Pathname?
34
+ def in_runtime_dir: (Pathname | String path) -> Pathname?
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ module Etcetera
2
+ module BaseStrategy
3
+ class Apple < Data
4
+ include _BaseStrategy
5
+
6
+ def self.new: (?home_dir: Pathname) -> instance
7
+ def initialize: (?home_dir: Pathname) -> void
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Etcetera
2
+ module BaseStrategy
3
+ class Windows < Data
4
+ include _BaseStrategy
5
+
6
+ def self.new: (?home_dir: Pathname) -> instance
7
+ def initialize: (?home_dir: Pathname) -> void
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Etcetera
2
+ module BaseStrategy
3
+ class Xdg < Data
4
+ include _BaseStrategy
5
+
6
+ def self.new: (?home_dir: Pathname) -> instance
7
+ def initialize: (?home_dir: Pathname) -> void
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module Etcetera
2
+ # Provides configuration, data, and cache directories of the current user.
3
+ interface _BaseStrategy
4
+ def home_dir: () -> Pathname
5
+ def config_dir: () -> Pathname
6
+ def data_dir: () -> Pathname
7
+ def cache_dir: () -> Pathname
8
+ def state_dir: () -> Pathname?
9
+ def runtime_dir: () -> Pathname?
10
+ end
11
+
12
+ # These strategies simply provide the user’s configuration, data, and cache directories, without knowing about the application specifically.
13
+ module BaseStrategy
14
+ def self.choose_native_strategy: () -> native_base_strategy
15
+ def self.choose_base_strategy: () -> default_base_strategy
16
+ end
17
+ end
data/sig/etcetera.rbs ADDED
@@ -0,0 +1,32 @@
1
+ module Etcetera
2
+ # Version of the gem, mirroring the version of the Rust crate it ports.
3
+ VERSION: String
4
+
5
+ # This error occurs when the home directory cannot be located.
6
+ class HomeDirError < StandardError
7
+ def initialize: (?String message) -> void
8
+ end
9
+
10
+ # The strategy Etcetera::BaseStrategy.choose_native_strategy returns.
11
+ type native_base_strategy = BaseStrategy::Apple | BaseStrategy::Windows | BaseStrategy::Xdg
12
+
13
+ # The strategy Etcetera::BaseStrategy.choose_base_strategy returns.
14
+ type default_base_strategy = BaseStrategy::Windows | BaseStrategy::Xdg
15
+
16
+ # The strategy Etcetera::AppStrategy.choose_native_strategy returns.
17
+ type native_app_strategy = AppStrategy::Apple | AppStrategy::Windows | AppStrategy::Xdg
18
+
19
+ # The strategy Etcetera::AppStrategy.choose_app_strategy returns.
20
+ type default_app_strategy = AppStrategy::Windows | AppStrategy::Xdg
21
+
22
+ AppStrategyArgs: singleton(AppStrategy::AppStrategyArgs)
23
+
24
+ # A convenience function that wraps the home function from the standard library.
25
+ def self.home_dir: () -> Pathname
26
+
27
+ # Returns the current OS's default Etcetera::BaseStrategy.
28
+ def self.choose_base_strategy: () -> default_base_strategy
29
+
30
+ # Returns the current OS's default Etcetera::AppStrategy.
31
+ def self.choose_app_strategy: (AppStrategy::AppStrategyArgs args) -> default_app_strategy
32
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etcetera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.12.0
5
+ platform: ruby
6
+ authors:
7
+ - Kerrick Long
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: fiddle
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.1'
26
+ description: |
27
+ An unopinionated library for obtaining configuration, data, cache, & other
28
+ directories. Etcetera supports the XDG base directory specification, Apple's
29
+ Standard Directories, Windows' Known Folder Locations, and the Unix
30
+ single-folder convention, and lets you choose which to follow.
31
+ email:
32
+ - me@kerricklong.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - ".github/workflows/ci.yaml"
38
+ - CHANGELOG.md
39
+ - CODE_OF_CONDUCT.md
40
+ - LICENSE-APACHE
41
+ - LICENSE-MIT
42
+ - LICENSE-WINDOWS-SYS
43
+ - README.md
44
+ - Rakefile
45
+ - lib/etcetera.rb
46
+ - lib/etcetera/app_strategy.rb
47
+ - lib/etcetera/app_strategy/apple.rb
48
+ - lib/etcetera/app_strategy/unix.rb
49
+ - lib/etcetera/app_strategy/windows.rb
50
+ - lib/etcetera/app_strategy/xdg.rb
51
+ - lib/etcetera/base_strategy.rb
52
+ - lib/etcetera/base_strategy/apple.rb
53
+ - lib/etcetera/base_strategy/windows.rb
54
+ - lib/etcetera/base_strategy/xdg.rb
55
+ - lib/etcetera/version.rb
56
+ - lib/etcetera/windows_sys.rb
57
+ - sig/etcetera.rbs
58
+ - sig/etcetera/app_strategy.rbs
59
+ - sig/etcetera/app_strategy/apple.rbs
60
+ - sig/etcetera/app_strategy/unix.rbs
61
+ - sig/etcetera/app_strategy/windows.rbs
62
+ - sig/etcetera/app_strategy/xdg.rbs
63
+ - sig/etcetera/base_strategy.rbs
64
+ - sig/etcetera/base_strategy/apple.rbs
65
+ - sig/etcetera/base_strategy/windows.rbs
66
+ - sig/etcetera/base_strategy/xdg.rbs
67
+ homepage: https://github.com/Kerrick/etcetera_rb
68
+ licenses:
69
+ - MIT
70
+ - Apache-2.0
71
+ metadata:
72
+ source_code_uri: https://github.com/Kerrick/etcetera_rb
73
+ changelog_uri: https://github.com/Kerrick/etcetera_rb/blob/ruby/CHANGELOG.md
74
+ documentation_uri: https://rubydoc.info/gems/etcetera
75
+ rubygems_mfa_required: 'true'
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 4.0.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 4.0.22
91
+ specification_version: 4
92
+ summary: An unopinionated library for obtaining configuration, data, cache, & other
93
+ directories
94
+ test_files: []