fedux_org-stdlib 0.8.6 → 0.8.7
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/directory_finder.rb +17 -17
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/directory_finder_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e5236b00e36418b04fedb9fdabc64f7dff9c0ae
|
4
|
+
data.tar.gz: d9883b7a10db200d561bde6567a79c281427785a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0975a290e2fb2a14534a3d32a56de64039aa733b1e3dd58b248f44acfcd2502930c8e54929384bed248123beeb4a166fd7ec9417825999bba59854a40b38d21
|
7
|
+
data.tar.gz: 0e2acdd1cca4c126b12e199bc8f3d8d930f137eb504f2e1225271ae5cd7a486c5a0093461d47a5dc2f1cdf410a74c67dcc418bf98c6190780d696619e686b00a
|
data/Gemfile.lock
CHANGED
@@ -33,7 +33,7 @@ module FeduxOrgStdlib
|
|
33
33
|
# If you want the class to look for your config file at a different place
|
34
34
|
# overwrite the following method
|
35
35
|
#
|
36
|
-
# *
|
36
|
+
# * allowed_directory_paths
|
37
37
|
#
|
38
38
|
# Below you find some examples for the usage of the class:
|
39
39
|
#
|
@@ -45,7 +45,7 @@ module FeduxOrgStdlib
|
|
45
45
|
class DirectoryFinder
|
46
46
|
# Create a new instance of config
|
47
47
|
#
|
48
|
-
# It tries to find a suitable
|
48
|
+
# It tries to find a suitable directory. If it doesn't find one
|
49
49
|
# the config is empty and uses the defaults defined within a config class
|
50
50
|
#
|
51
51
|
# @param [String] file
|
@@ -69,18 +69,18 @@ module FeduxOrgStdlib
|
|
69
69
|
)
|
70
70
|
@logger = logger
|
71
71
|
@working_directory = working_directory
|
72
|
-
@directory ||= (directory ||
|
72
|
+
@directory ||= (directory || _available_directory)
|
73
73
|
|
74
74
|
unless directory
|
75
|
-
logger.debug "No
|
75
|
+
logger.debug "No config directory found at #{_allowed_directory_paths.to_list}, therefor I'm going to use an empty config object instead."
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
# Return the path to the preferred
|
79
|
+
# Return the path to the preferred config file
|
80
80
|
# @return [String]
|
81
|
-
# The path to the preferred
|
82
|
-
def
|
83
|
-
|
81
|
+
# The path to the preferred config file
|
82
|
+
def preferred_directory
|
83
|
+
_allowed_directory_paths.first
|
84
84
|
end
|
85
85
|
|
86
86
|
private
|
@@ -96,7 +96,7 @@ module FeduxOrgStdlib
|
|
96
96
|
# class ClientDirectory; end
|
97
97
|
#
|
98
98
|
# This will result in `client` as base name for the config file.
|
99
|
-
def
|
99
|
+
def _directory
|
100
100
|
unless (name = _class_name.sub(/Directory/, '').underscore).blank?
|
101
101
|
return name
|
102
102
|
end
|
@@ -126,13 +126,13 @@ module FeduxOrgStdlib
|
|
126
126
|
# @return [Array]
|
127
127
|
# A list of paths where the config object should look for its config
|
128
128
|
# file.
|
129
|
-
def
|
129
|
+
def _allowed_directory_paths
|
130
130
|
[
|
131
|
-
::File.expand_path(::File.join('~', '.config', _application_name,
|
132
|
-
::File.expand_path(::File.join('~', format('.%s', _application_name),
|
133
|
-
::File.expand_path(::File.join('~', format('.%s',
|
134
|
-
::File.expand_path(::File.join('/etc', _application_name,
|
135
|
-
::File.expand_path(::File.join(working_directory,
|
131
|
+
::File.expand_path(::File.join('~', '.config', _application_name, _directory)),
|
132
|
+
::File.expand_path(::File.join('~', format('.%s', _application_name), _directory)),
|
133
|
+
::File.expand_path(::File.join('~', format('.%s', _directory))),
|
134
|
+
::File.expand_path(::File.join('/etc', _application_name, _directory)),
|
135
|
+
::File.expand_path(::File.join(working_directory, _directory))
|
136
136
|
]
|
137
137
|
end
|
138
138
|
|
@@ -144,8 +144,8 @@ module FeduxOrgStdlib
|
|
144
144
|
self.class.to_s.deconstantize
|
145
145
|
end
|
146
146
|
|
147
|
-
def
|
148
|
-
|
147
|
+
def _available_directory
|
148
|
+
_allowed_directory_paths.find { |f| ::File.directory? f }
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -18,7 +18,7 @@ RSpec.describe DirectoryFinder do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
config = config_klass.new
|
21
|
-
expect(config.
|
21
|
+
expect(config.preferred_directory).to eq File.expand_path('~/.config/my_application/test')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -36,7 +36,7 @@ RSpec.describe DirectoryFinder do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
config = config_klass.new
|
39
|
-
expect(config.
|
39
|
+
expect(config.preferred_directory).to eq File.expand_path('~/.config/my_application/my_sub/test')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|