easy_app_helper 1.0.4 → 1.0.5
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/.travis.yml +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +5 -2
- data/easy_app_helper.gemspec +1 -1
- data/lib/easy_app_helper/core/base.rb +2 -0
- data/lib/easy_app_helper/core/config.rb +3 -4
- data/lib/easy_app_helper/core/logger.rb +4 -4
- data/lib/easy_app_helper/core/places.rb +5 -4
- data/lib/easy_app_helper/version.rb +1 -1
- data/spec/config_spec.rb +22 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ecbc48dfd4704a478842023bb560f06c271bf05
|
4
|
+
data.tar.gz: 903c92b33e0a73983a1be10634fb15c24e506d89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cde655e0c910beddfd6708ab94072d766e09094dc0d8d24f0dfe887f56dee45e1277ca5d78321f7385cf6c2270eefc224e091d7fc868a0b251c7ad4dd0d475c9
|
7
|
+
data.tar.gz: 86f57ebfa4d5046977f0e392b43239630e09189f1e79422c13dfae6bfd15abf0f8ee0d6b463cc556c75a8f977e3ccc0dd5ba6035b1de936861c53345551fa570
|
data/.travis.yml
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# EasyAppHelper
|
2
2
|
|
3
|
+
[](https://travis-ci.org/lbriais/easy_app_helper)
|
4
|
+
[](http://badge.fury.io/rb/easy_app_helper)
|
5
|
+
|
3
6
|
**This [gem][EAP] aims at providing useful helpers for command line applications.**
|
4
7
|
|
5
8
|
This is a complete rewrite of the initial easy_app_helper gem. **It is not compatible with
|
@@ -23,7 +26,7 @@ The new **EasyAppHelper** module provides:
|
|
23
26
|
line in a **dedicated layer of the config object**.
|
24
27
|
* A mechanism that ensures that as soon as you access any of the objects or methods exposed by EasyAppHelper,
|
25
28
|
all of them are **fully configured and ready to be used**.
|
26
|
-
|
29
|
+
|
27
30
|
If you are writing command line applications, I hope you will like it because it's very easy to use,
|
28
31
|
and as unobtrusive as possible (you choose when you want to include or use as a module) while providing
|
29
32
|
a ready-for-prod config, logger and command line management.
|
@@ -118,7 +121,7 @@ puts config.internal_configs.to_yaml
|
|
118
121
|
#:specific_file:
|
119
122
|
# :content: {}
|
120
123
|
|
121
|
-
# You see of course that the
|
124
|
+
# You see of course that the three modifications we did appear actually in the modified sub-hash
|
122
125
|
# And now the merged config
|
123
126
|
puts config.to_hash
|
124
127
|
|
data/easy_app_helper.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler"
|
@@ -86,6 +86,7 @@ class EasyAppHelper::Core::Base
|
|
86
86
|
# Sets the :command_line layer of internal_configs to the computed {#command_line_config}
|
87
87
|
def load_config
|
88
88
|
internal_configs[:command_line] = {content: command_line_config, source: 'Command line'}
|
89
|
+
self
|
89
90
|
end
|
90
91
|
|
91
92
|
# Any modification done to the config is in fact stored in the :modified layer of internal_configs
|
@@ -98,6 +99,7 @@ class EasyAppHelper::Core::Base
|
|
98
99
|
# Reset the :modified layer of internal_configs rolling back any change done to the config
|
99
100
|
def reset
|
100
101
|
internal_configs[:modified] = {content: {}, source: CHANGED_BY_CODE}
|
102
|
+
self
|
101
103
|
end
|
102
104
|
|
103
105
|
|
@@ -42,14 +42,12 @@ require 'easy_app_helper/core/merge_policies'
|
|
42
42
|
|
43
43
|
class EasyAppHelper::Core::Config
|
44
44
|
include EasyAppHelper::Core::HashesMergePolicies
|
45
|
-
include EasyAppHelper::Core::Config::Places.
|
45
|
+
include EasyAppHelper::Core::Config::Places.get_os_module
|
46
46
|
|
47
47
|
ADMIN_CONFIG_FILENAME = EasyAppHelper.name
|
48
48
|
|
49
|
-
|
50
49
|
# Potential extensions a config file can have
|
51
50
|
CONFIG_FILE_POSSIBLE_EXTENSIONS = %w(conf yml cfg yaml CFG YML YAML Yaml)
|
52
|
-
ADMIN_CONFIG_FILENAME
|
53
51
|
|
54
52
|
# @param [EasyAppHelper::Core::Logger] logger
|
55
53
|
# The logger passed to this constructor should be a temporary logger until the full config is loaded.
|
@@ -85,6 +83,7 @@ class EasyAppHelper::Core::Config
|
|
85
83
|
load_layer_config :global, script_filename, force
|
86
84
|
load_layer_config :user, script_filename, force
|
87
85
|
load_layer_config :specific_file, internal_configs[:command_line][:content][:'config-file'], force
|
86
|
+
self
|
88
87
|
end
|
89
88
|
|
90
89
|
# @see #load_config
|
@@ -117,7 +116,7 @@ class EasyAppHelper::Core::Config
|
|
117
116
|
# @param [Object] key: The key to access the data in the merged_config hash (see {#to_hash})
|
118
117
|
# @return [String] Value for this key in the merged config.
|
119
118
|
def [](key = nil)
|
120
|
-
key.nil? ?
|
119
|
+
key.nil? ? to_hash : to_hash[key]
|
121
120
|
end
|
122
121
|
|
123
122
|
|
@@ -12,7 +12,7 @@ require 'singleton'
|
|
12
12
|
# to the definitive one.
|
13
13
|
# TODO: Ensure only the messages that are above the current level are displayed when handing over to the definitive logger.
|
14
14
|
class Logger
|
15
|
-
def
|
15
|
+
def hand_over_to(log)
|
16
16
|
history = []
|
17
17
|
history = @logdev.dev.history if @logdev.dev.respond_to? :history
|
18
18
|
@logdev.close
|
@@ -58,11 +58,11 @@ class EasyAppHelper::Core::Logger < Logger
|
|
58
58
|
debug "Merged config:\n#{@config.to_yaml}"
|
59
59
|
if config[:debug]
|
60
60
|
if config[:'log-file']
|
61
|
-
|
61
|
+
hand_over_to config[:'log-file']
|
62
62
|
elsif config[:"debug-on-err"]
|
63
|
-
|
63
|
+
hand_over_to STDERR
|
64
64
|
else
|
65
|
-
|
65
|
+
hand_over_to STDOUT
|
66
66
|
end
|
67
67
|
else
|
68
68
|
close
|
@@ -32,7 +32,7 @@ class EasyAppHelper::Core::Config::Places
|
|
32
32
|
system: ["#{ENV['systemRoot']}/Config"],
|
33
33
|
|
34
34
|
# Where could be stored global configuration
|
35
|
-
global: ['
|
35
|
+
global: ["#{ENV['systemRoot']}/Config",
|
36
36
|
"#{ENV['ALLUSERSPROFILE']}/Application Data"],
|
37
37
|
|
38
38
|
# Where could be stored user configuration
|
@@ -40,12 +40,13 @@ class EasyAppHelper::Core::Config::Places
|
|
40
40
|
}
|
41
41
|
end
|
42
42
|
|
43
|
-
CONF ={
|
44
|
-
mingw32: Windows
|
43
|
+
CONF = {
|
44
|
+
mingw32: Windows,
|
45
|
+
linux: Unix
|
45
46
|
}
|
46
47
|
DEFAULT = Unix
|
47
48
|
|
48
|
-
def self.
|
49
|
+
def self.get_os_module
|
49
50
|
conf = CONF[RbConfig::CONFIG['target_os'].to_sym]
|
50
51
|
conf.nil? ? DEFAULT : conf
|
51
52
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -41,7 +41,7 @@ describe EasyAppHelper.config do
|
|
41
41
|
expect(subject[:stupid_conf]).to eq SAMPLE_STRING
|
42
42
|
end
|
43
43
|
|
44
|
-
it 'should be reloaded when :config-file property changes
|
44
|
+
it 'should be reloaded when :config-file property changes' do
|
45
45
|
subject.should_receive(:force_reload)
|
46
46
|
subject[:'config-file'] = SAMPLE_STRING
|
47
47
|
end
|
@@ -66,14 +66,14 @@ describe EasyAppHelper.config do
|
|
66
66
|
original_ordered_layers = [:modified, :command_line, :specific_file, :user, :global, :system]
|
67
67
|
layers = original_ordered_layers.dup
|
68
68
|
original_ordered_layers.each do |layer|
|
69
|
-
test_descr = "should find the data in #{layer} if present in #{layer}"
|
69
|
+
test_descr = "should find the data in #{layer} layer if present in #{layer} layer"
|
70
70
|
unless layers.length == original_ordered_layers.length
|
71
71
|
already_removed = original_ordered_layers - layers
|
72
72
|
if already_removed.length == 1
|
73
|
-
test_descr += " and #{already_removed[0]}
|
73
|
+
test_descr += " and not present in #{already_removed[0]} layer"
|
74
74
|
end
|
75
75
|
if already_removed.length > 1
|
76
|
-
test_descr += " and #{already_removed.join ', '}
|
76
|
+
test_descr += " and not present in #{already_removed.join ', '} layers"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -125,4 +125,22 @@ describe EasyAppHelper.config do
|
|
125
125
|
|
126
126
|
end
|
127
127
|
|
128
|
+
context "when reloaded (forced)" do
|
129
|
+
|
130
|
+
it "should keep all modifications done the standard way" do
|
131
|
+
subject[:test_remove] = SAMPLE_STRING
|
132
|
+
subject.force_reload
|
133
|
+
expect(subject[:test_remove]).to eq SAMPLE_STRING
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should remove all modifications directly done on internal layers" do
|
137
|
+
subject.internal_configs[:system][:content][:stupid_conf] = SAMPLE_STRING
|
138
|
+
subject.internal_configs[:command_line][:content][:stupid_conf] = SAMPLE_STRING
|
139
|
+
subject.force_reload
|
140
|
+
expect(subject.internal_configs[:system][:content][:stupid_conf]).to be_nil
|
141
|
+
expect(subject.internal_configs[:command_line][:content][:stupid_conf]).to be_nil
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
128
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_app_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L.Briais
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- .gitignore
|
91
|
+
- .travis.yml
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE.txt
|
93
94
|
- README.md
|
@@ -134,6 +135,8 @@ specification_version: 4
|
|
134
135
|
summary: Provides cool helpers to your application, including configuration and logging
|
135
136
|
features
|
136
137
|
test_files:
|
138
|
+
- spec/config_spec.rb
|
139
|
+
- spec/logger_spec.rb
|
137
140
|
- test/test.yml
|
138
141
|
- test/test2_app.rb
|
139
142
|
- test/test3_app.rb
|