ae_easy-config 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,88 +0,0 @@
1
- module AeEasy
2
- module Config
3
- # Manage configuration from a file.
4
- class Local
5
- # Configuration loaded from local configuarion file (see #load).
6
- #
7
- # @return [Hash,nil] `nil` when nothing has been loaded.
8
- attr_reader :local
9
-
10
- # Clear cache.
11
- def self.clear_cache
12
- @@local = {}
13
- end
14
-
15
- # Convert to hash.
16
- #
17
- # @return [Hash]
18
- def to_h
19
- local
20
- end
21
-
22
- # Load into or from cache a configuration file contents.
23
- #
24
- # @param [String] file_path Configuration file path.
25
- # @param [Hash] opts ({}) Configuration options.
26
- # @option opts [Boolean] :force (false) Will reload configuration file
27
- # when `true`.
28
- #
29
- # @return [Hash] Configuration file contents.
30
- def self.load_file file_path, opts = {}
31
- opts = {
32
- force: false
33
- }.merge opts
34
- key = file_path = File.expand_path file_path
35
- @@local ||= {}
36
- return @@local[key] if !opts[:force] && @@local.has_key?(key)
37
-
38
- @@local[key] = YAML.load_file(file_path) || {}
39
- @@local[key].freeze
40
- end
41
-
42
- # Get configuration key contents.
43
- #
44
- # @param [String] key Configuration option key.
45
- #
46
- # @return [Object,nil]
47
- def [](key)
48
- local[key]
49
- end
50
-
51
- # Local configuration file path.
52
- #
53
- # @return [String] Configuration local file path. Default is
54
- # `./ae_easy.yaml`
55
- def file_path
56
- @file_path ||= File.expand_path(File.join('.', 'ae_easy.yaml'))
57
- end
58
-
59
- # Loads a local configuration file.
60
- #
61
- # @param [Hash] opts ({}) Configuration options.
62
- # @option opts [String] :file_path (nil) Configuration file path to load (see
63
- # #file_path for configuration default file.)
64
- # @option opts [Boolean] :force (false) Will reload configuration file
65
- # when `true`.
66
- def load opts = {}
67
- opts = {
68
- file_path: nil,
69
- force: false
70
- }.merge opts
71
- @file_path = opts[:file_path] || file_path
72
- @local = self.class.load_file(file_path, opts)
73
- end
74
-
75
- # Reloads local configuration file.
76
- def reload
77
- load force: true
78
- end
79
-
80
- # Initialize.
81
- #
82
- # @param [Hash] opts ({}) Configuration options (see #load).
83
- def initialize opts = {}
84
- load opts
85
- end
86
- end
87
- end
88
- end
@@ -1,6 +0,0 @@
1
- module AeEasy
2
- module Config
3
- # Gem version
4
- VERSION = "0.0.3"
5
- end
6
- end