ae_easy-config 0.0.3 → 0.0.4
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/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +1 -1
- data/README.md +8 -4
- data/Rakefile +0 -10
- data/ae_easy-config.gemspec +6 -9
- data/lib/ae_easy/config.rb +6 -7
- metadata +26 -71
- data/doc/AeEasy.html +0 -117
- data/doc/AeEasy/Config.html +0 -144
- data/doc/AeEasy/Config/Local.html +0 -1049
- data/doc/_index.html +0 -137
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -496
- data/doc/file.README.html +0 -91
- data/doc/file_list.html +0 -56
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -91
- data/doc/js/app.js +0 -292
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -123
- data/doc/top-level-namespace.html +0 -110
- data/lib/ae_easy/config/local.rb +0 -88
- data/lib/ae_easy/config/version.rb +0 -6
data/lib/ae_easy/config/local.rb
DELETED
@@ -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
|