easy_app_helper 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +47 -47
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +498 -498
- data/Rakefile +1 -1
- data/easy_app_helper.gemspec +26 -26
- data/lib/easy_app_helper/core/base.rb +141 -128
- data/lib/easy_app_helper/core/config.rb +203 -203
- data/lib/easy_app_helper/core/logger.rb +111 -103
- data/lib/easy_app_helper/core/merge_policies.rb +37 -37
- data/lib/easy_app_helper/core/places.rb +51 -51
- data/lib/easy_app_helper/module_manager.rb +67 -60
- data/lib/easy_app_helper/version.rb +10 -10
- data/lib/easy_app_helper.rb +20 -20
- data/test/test.yml +7 -7
- data/test/test2_app.rb +33 -33
- data/test/test3_app.rb +90 -90
- data/test/test4_app.rb +35 -35
- data/test/test_app.rb +55 -55
- metadata +2 -3
@@ -1,37 +1,37 @@
|
|
1
|
-
################################################################################
|
2
|
-
# EasyAppHelper
|
3
|
-
#
|
4
|
-
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
-
# http://opensource.org/licenses/MIT
|
6
|
-
################################################################################
|
7
|
-
|
8
|
-
# This module proposes different merge policies for two hashes.
|
9
|
-
module EasyAppHelper::Core::HashesMergePolicies
|
10
|
-
|
11
|
-
# Performs a merge at the second level of hashes.
|
12
|
-
# simple entries and arrays are overridden.
|
13
|
-
def hashes_second_level_merge(h1, h2)
|
14
|
-
h2.each do |key, v|
|
15
|
-
if h1[key] and h1[key].is_a?(Hash)
|
16
|
-
# Merges hashes
|
17
|
-
h1[key].merge! h2[key]
|
18
|
-
else
|
19
|
-
# Overrides the rest
|
20
|
-
h1[key] = h2[key] unless h2[key].nil?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
h1
|
24
|
-
end
|
25
|
-
|
26
|
-
# Uses the standard "merge!" method
|
27
|
-
def simple_merge(h1, h2)
|
28
|
-
h1.merge! h2
|
29
|
-
end
|
30
|
-
|
31
|
-
# Brutal override
|
32
|
-
def override_merge(h1, h2)
|
33
|
-
h1 = nil
|
34
|
-
h1 = h2
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
1
|
+
################################################################################
|
2
|
+
# EasyAppHelper
|
3
|
+
#
|
4
|
+
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
+
# http://opensource.org/licenses/MIT
|
6
|
+
################################################################################
|
7
|
+
|
8
|
+
# This module proposes different merge policies for two hashes.
|
9
|
+
module EasyAppHelper::Core::HashesMergePolicies
|
10
|
+
|
11
|
+
# Performs a merge at the second level of hashes.
|
12
|
+
# simple entries and arrays are overridden.
|
13
|
+
def hashes_second_level_merge(h1, h2)
|
14
|
+
h2.each do |key, v|
|
15
|
+
if h1[key] and h1[key].is_a?(Hash)
|
16
|
+
# Merges hashes
|
17
|
+
h1[key].merge! h2[key]
|
18
|
+
else
|
19
|
+
# Overrides the rest
|
20
|
+
h1[key] = h2[key] unless h2[key].nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
h1
|
24
|
+
end
|
25
|
+
|
26
|
+
# Uses the standard "merge!" method
|
27
|
+
def simple_merge(h1, h2)
|
28
|
+
h1.merge! h2
|
29
|
+
end
|
30
|
+
|
31
|
+
# Brutal override
|
32
|
+
def override_merge(h1, h2)
|
33
|
+
h1 = nil
|
34
|
+
h1 = h2
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
################################################################################
|
2
|
-
# EasyAppHelper
|
3
|
-
#
|
4
|
-
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
-
# http://opensource.org/licenses/MIT
|
6
|
-
################################################################################
|
7
|
-
|
8
|
-
# Possible places regarding the OS
|
9
|
-
# TODO: Add equivalent for Mac
|
10
|
-
class EasyAppHelper::Core::Config::Places
|
11
|
-
module Unix
|
12
|
-
# Where could be stored admin configuration that rules all EasyAppHelper
|
13
|
-
# based applications.
|
14
|
-
POSSIBLE_PLACES = {
|
15
|
-
|
16
|
-
system: ["/etc"],
|
17
|
-
|
18
|
-
# Where could be stored global wide configuration
|
19
|
-
global: ["/etc",
|
20
|
-
"/usr/local/etc"],
|
21
|
-
|
22
|
-
# Where could be stored user configuration
|
23
|
-
user: ["#{ENV['HOME']}/.config"]
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
module Windows
|
28
|
-
# Where could be stored admin configuration that rules all EasyAppHelper
|
29
|
-
# based applications.
|
30
|
-
POSSIBLE_PLACES = {
|
31
|
-
|
32
|
-
system: ["#{ENV['systemRoot']}/Config"],
|
33
|
-
|
34
|
-
# Where could be stored global configuration
|
35
|
-
global: ['C:/Windows/Config',
|
36
|
-
"#{ENV['ALLUSERSPROFILE']}/Application Data"],
|
37
|
-
|
38
|
-
# Where could be stored user configuration
|
39
|
-
user: [ENV['APPDATA']]
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
CONF ={
|
44
|
-
mingw32: Windows
|
45
|
-
}
|
46
|
-
DEFAULT = Unix
|
47
|
-
|
48
|
-
def self.get_OS_module
|
49
|
-
conf = CONF[RbConfig::CONFIG['target_os'].to_sym]
|
50
|
-
conf.nil? ? DEFAULT : conf
|
51
|
-
end
|
1
|
+
################################################################################
|
2
|
+
# EasyAppHelper
|
3
|
+
#
|
4
|
+
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
+
# http://opensource.org/licenses/MIT
|
6
|
+
################################################################################
|
7
|
+
|
8
|
+
# Possible places regarding the OS
|
9
|
+
# TODO: Add equivalent for Mac
|
10
|
+
class EasyAppHelper::Core::Config::Places
|
11
|
+
module Unix
|
12
|
+
# Where could be stored admin configuration that rules all EasyAppHelper
|
13
|
+
# based applications.
|
14
|
+
POSSIBLE_PLACES = {
|
15
|
+
|
16
|
+
system: ["/etc"],
|
17
|
+
|
18
|
+
# Where could be stored global wide configuration
|
19
|
+
global: ["/etc",
|
20
|
+
"/usr/local/etc"],
|
21
|
+
|
22
|
+
# Where could be stored user configuration
|
23
|
+
user: ["#{ENV['HOME']}/.config"]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
module Windows
|
28
|
+
# Where could be stored admin configuration that rules all EasyAppHelper
|
29
|
+
# based applications.
|
30
|
+
POSSIBLE_PLACES = {
|
31
|
+
|
32
|
+
system: ["#{ENV['systemRoot']}/Config"],
|
33
|
+
|
34
|
+
# Where could be stored global configuration
|
35
|
+
global: ['C:/Windows/Config',
|
36
|
+
"#{ENV['ALLUSERSPROFILE']}/Application Data"],
|
37
|
+
|
38
|
+
# Where could be stored user configuration
|
39
|
+
user: [ENV['APPDATA']]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
CONF ={
|
44
|
+
mingw32: Windows
|
45
|
+
}
|
46
|
+
DEFAULT = Unix
|
47
|
+
|
48
|
+
def self.get_OS_module
|
49
|
+
conf = CONF[RbConfig::CONFIG['target_os'].to_sym]
|
50
|
+
conf.nil? ? DEFAULT : conf
|
51
|
+
end
|
52
52
|
end
|
@@ -1,61 +1,68 @@
|
|
1
|
-
################################################################################
|
2
|
-
# EasyAppHelper
|
3
|
-
#
|
4
|
-
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
-
# http://opensource.org/licenses/MIT
|
6
|
-
################################################################################
|
7
|
-
|
8
|
-
module EasyAppHelper::Core
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'easy_app_helper/core/logger'
|
13
|
-
require 'easy_app_helper/core/base'
|
14
|
-
require 'easy_app_helper/core/config'
|
15
|
-
|
16
|
-
# This module contains the exposed methods of the framework
|
17
|
-
# It is included and extended into EasyAppHelper
|
18
|
-
module EasyAppHelper::ModuleManager
|
19
|
-
|
20
|
-
# @return [EasyAppHelper::Core::Logger] The application logger
|
21
|
-
def logger
|
22
|
-
@@logger
|
23
|
-
end
|
24
|
-
|
25
|
-
# @return [EasyAppHelper::Core::Config] The application config
|
26
|
-
def config
|
27
|
-
@@config
|
28
|
-
end
|
29
|
-
|
30
|
-
# Convenient method that logs at info level, but also outputs the message to STDOUT if
|
31
|
-
# verbose is set in the config.
|
32
|
-
# @param [String] msg to be displayed
|
33
|
-
def puts_and_logs(msg)
|
34
|
-
@@logger.puts_and_logs msg
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@@
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
1
|
+
################################################################################
|
2
|
+
# EasyAppHelper
|
3
|
+
#
|
4
|
+
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
+
# http://opensource.org/licenses/MIT
|
6
|
+
################################################################################
|
7
|
+
|
8
|
+
module EasyAppHelper::Core
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'easy_app_helper/core/logger'
|
13
|
+
require 'easy_app_helper/core/base'
|
14
|
+
require 'easy_app_helper/core/config'
|
15
|
+
|
16
|
+
# This module contains the exposed methods of the framework
|
17
|
+
# It is included and extended into EasyAppHelper
|
18
|
+
module EasyAppHelper::ModuleManager
|
19
|
+
|
20
|
+
# @return [EasyAppHelper::Core::Logger] The application logger
|
21
|
+
def logger
|
22
|
+
@@logger
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [EasyAppHelper::Core::Config] The application config
|
26
|
+
def config
|
27
|
+
@@config
|
28
|
+
end
|
29
|
+
|
30
|
+
# Convenient method that logs at info level, but also outputs the message to STDOUT if
|
31
|
+
# verbose is set in the config.
|
32
|
+
# @param [String] msg to be displayed
|
33
|
+
def puts_and_logs(msg)
|
34
|
+
@@logger.puts_and_logs msg
|
35
|
+
end
|
36
|
+
|
37
|
+
# Method to do something (expects a block) unless --simulate is specified on the command line.
|
38
|
+
# See {EasyAppHelper::Core::Base#safely_exec original implementation}.
|
39
|
+
def safely_exec(message, *args, &block)
|
40
|
+
@@config.safely_exec message, *args, &block
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def self.included(base)
|
45
|
+
init_core_modules
|
46
|
+
base.extend self
|
47
|
+
end
|
48
|
+
|
49
|
+
################################################################################
|
50
|
+
private
|
51
|
+
|
52
|
+
def self.init_logger
|
53
|
+
@@logger ||= EasyAppHelper::Core::Logger.instance
|
54
|
+
@@logger
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.init_config
|
58
|
+
@@config ||= EasyAppHelper::Core::Config.new @@logger
|
59
|
+
@@logger.set_app_config(@@config)
|
60
|
+
@@config
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.init_core_modules
|
64
|
+
init_logger
|
65
|
+
init_config
|
66
|
+
end
|
67
|
+
|
61
68
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
################################################################################
|
2
|
-
# EasyAppHelper
|
3
|
-
#
|
4
|
-
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
-
# http://opensource.org/licenses/MIT
|
6
|
-
################################################################################
|
7
|
-
|
8
|
-
module EasyAppHelper
|
9
|
-
EASY_APP_HELPER_VERSION = "1.0.
|
10
|
-
end
|
1
|
+
################################################################################
|
2
|
+
# EasyAppHelper
|
3
|
+
#
|
4
|
+
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
+
# http://opensource.org/licenses/MIT
|
6
|
+
################################################################################
|
7
|
+
|
8
|
+
module EasyAppHelper
|
9
|
+
EASY_APP_HELPER_VERSION = "1.0.3"
|
10
|
+
end
|
data/lib/easy_app_helper.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
################################################################################
|
2
|
-
# EasyAppHelper
|
3
|
-
#
|
4
|
-
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
-
# http://opensource.org/licenses/MIT
|
6
|
-
################################################################################
|
7
|
-
|
8
|
-
require 'easy_app_helper/version'
|
9
|
-
|
10
|
-
# When this module is included in any class, it mixes in automatically
|
11
|
-
# EasyAppHelper::ModuleManager methods both into the
|
12
|
-
# instance and the class of the instance that includes it.
|
13
|
-
# Thus to have access to the helper methods, the only requirement is to include
|
14
|
-
# this module...
|
15
|
-
module EasyAppHelper
|
16
|
-
require 'easy_app_helper/module_manager'
|
17
|
-
include ModuleManager
|
18
|
-
end
|
19
|
-
|
20
|
-
|
1
|
+
################################################################################
|
2
|
+
# EasyAppHelper
|
3
|
+
#
|
4
|
+
# Copyright (c) 2013 L.Briais under MIT license
|
5
|
+
# http://opensource.org/licenses/MIT
|
6
|
+
################################################################################
|
7
|
+
|
8
|
+
require 'easy_app_helper/version'
|
9
|
+
|
10
|
+
# When this module is included in any class, it mixes in automatically
|
11
|
+
# EasyAppHelper::ModuleManager methods both into the
|
12
|
+
# instance and the class of the instance that includes it.
|
13
|
+
# Thus to have access to the helper methods, the only requirement is to include
|
14
|
+
# this module...
|
15
|
+
module EasyAppHelper
|
16
|
+
require 'easy_app_helper/module_manager'
|
17
|
+
include ModuleManager
|
18
|
+
end
|
19
|
+
|
20
|
+
|
data/test/test.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
stupid_config: true
|
2
|
-
|
3
|
-
pipo: bimbo
|
4
|
-
|
5
|
-
hash_example:
|
6
|
-
first: one
|
7
|
-
second: two
|
1
|
+
stupid_config: true
|
2
|
+
|
3
|
+
pipo: bimbo
|
4
|
+
|
5
|
+
hash_example:
|
6
|
+
first: one
|
7
|
+
second: two
|
data/test/test2_app.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
require 'easy_app_helper'
|
5
|
-
|
6
|
-
|
7
|
-
# EasyAppHelper.logger.level = 0
|
8
|
-
EasyAppHelper.puts_and_logs "Groovy baby !"
|
9
|
-
EasyAppHelper.config[:zboubi] = "Hi shared"
|
10
|
-
|
11
|
-
class A
|
12
|
-
include EasyAppHelper
|
13
|
-
|
14
|
-
def echo
|
15
|
-
puts_and_logs config[:zboubi]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
A.new.echo
|
20
|
-
EasyAppHelper.puts_and_logs EasyAppHelper.config[:zboubi]
|
21
|
-
|
22
|
-
include EasyAppHelper
|
23
|
-
puts_and_logs "ZBOUBI: #{config[:zboubi]}"
|
24
|
-
config.reset
|
25
|
-
puts_and_logs "ZBOUBI2: #{config[:zboubi]}"
|
26
|
-
|
27
|
-
puts config.to_yaml
|
28
|
-
config.script_filename = 'batch_audio_convert'
|
29
|
-
puts 'Internal configs'
|
30
|
-
puts config.internal_configs.to_yaml
|
31
|
-
puts 'Resulting config'
|
32
|
-
puts config.to_yaml
|
33
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
require 'easy_app_helper'
|
5
|
+
|
6
|
+
|
7
|
+
# EasyAppHelper.logger.level = 0
|
8
|
+
EasyAppHelper.puts_and_logs "Groovy baby !"
|
9
|
+
EasyAppHelper.config[:zboubi] = "Hi shared"
|
10
|
+
|
11
|
+
class A
|
12
|
+
include EasyAppHelper
|
13
|
+
|
14
|
+
def echo
|
15
|
+
puts_and_logs config[:zboubi]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
A.new.echo
|
20
|
+
EasyAppHelper.puts_and_logs EasyAppHelper.config[:zboubi]
|
21
|
+
|
22
|
+
include EasyAppHelper
|
23
|
+
puts_and_logs "ZBOUBI: #{config[:zboubi]}"
|
24
|
+
config.reset
|
25
|
+
puts_and_logs "ZBOUBI2: #{config[:zboubi]}"
|
26
|
+
|
27
|
+
puts config.to_yaml
|
28
|
+
config.script_filename = 'batch_audio_convert'
|
29
|
+
puts 'Internal configs'
|
30
|
+
puts config.internal_configs.to_yaml
|
31
|
+
puts 'Resulting config'
|
32
|
+
puts config.to_yaml
|
33
|
+
|
data/test/test3_app.rb
CHANGED
@@ -1,90 +1,90 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'easy_app_helper'
|
4
|
-
|
5
|
-
# You can directly access the config or the logger through the EasyAppHelper module
|
6
|
-
puts "The application verbose flag is #{EasyAppHelper.config[:verbose]}"
|
7
|
-
|
8
|
-
# You can directly use the logger according to the command line flags
|
9
|
-
# This will do nothing unless --debug is set and --log-level is set to the correct level
|
10
|
-
EasyAppHelper.logger.info "Hi guys!"
|
11
|
-
|
12
|
-
# Fed up with the EasyAppHelper prefix ? Just include the module where you want
|
13
|
-
include EasyAppHelper
|
14
|
-
|
15
|
-
# You can override programmatically any part of the config
|
16
|
-
config[:debug] = true
|
17
|
-
logger.level = 1
|
18
|
-
config[:test] = 'Groovy'
|
19
|
-
EasyAppHelper.logger.info "Hi guys!... again"
|
20
|
-
|
21
|
-
# You can see the internals of the config
|
22
|
-
puts config.internal_configs.to_yaml
|
23
|
-
# Which will output
|
24
|
-
#:modified:
|
25
|
-
# :content:
|
26
|
-
# :log-level: 1
|
27
|
-
# :debug: true
|
28
|
-
# :test: cool
|
29
|
-
# :source: Changed by code
|
30
|
-
#:command_line:
|
31
|
-
# :content:
|
32
|
-
# :auto:
|
33
|
-
# :simulate:
|
34
|
-
# :verbose: true
|
35
|
-
# :help:
|
36
|
-
# :config-file:
|
37
|
-
# :config-override:
|
38
|
-
# :debug:
|
39
|
-
# :debug-on-err:
|
40
|
-
# :log-level:
|
41
|
-
# :log-file:
|
42
|
-
# :source: Command line
|
43
|
-
#:system:
|
44
|
-
# :content: {}
|
45
|
-
# :source:
|
46
|
-
# :origin: EasyAppHelper
|
47
|
-
#:global:
|
48
|
-
# :content: {}
|
49
|
-
# :source:
|
50
|
-
# :origin: ''
|
51
|
-
#:user:
|
52
|
-
# :content: {}
|
53
|
-
# :source:
|
54
|
-
# :origin: ''
|
55
|
-
#:specific_file:
|
56
|
-
# :content: {}
|
57
|
-
|
58
|
-
# You see of course that the two modifications we did are in the modified sub-hash
|
59
|
-
# And now the merged config
|
60
|
-
puts config.to_hash
|
61
|
-
|
62
|
-
# But you can see the modified part as it is:
|
63
|
-
puts config.internal_configs[:modified]
|
64
|
-
|
65
|
-
# Of course you can access it from any class
|
66
|
-
class Dummy
|
67
|
-
include EasyAppHelper
|
68
|
-
|
69
|
-
def initialize
|
70
|
-
puts "#{config[:test]} baby !"
|
71
|
-
# Back to the original
|
72
|
-
config.reset
|
73
|
-
puts config.internal_configs[:modified]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
Dummy.new
|
78
|
-
|
79
|
-
# Some methods are provided to ease common tasks. For example this one will log at info level
|
80
|
-
# (so only displayed if debug mode and log level low enough), but will also puts on the console
|
81
|
-
# if verbose if set...
|
82
|
-
puts_and_logs "Hi world"
|
83
|
-
|
84
|
-
# It is actually one of the few methods added to regular Logger class (The added value of this logger
|
85
|
-
# is much more to be tightly coupled with the config object). Thus could access it like that:
|
86
|
-
logger.puts_and_logs "Hi world"
|
87
|
-
|
88
|
-
# or even
|
89
|
-
EasyAppHelper.logger.puts_and_logs "Hi world... 3 is enough."
|
90
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'easy_app_helper'
|
4
|
+
|
5
|
+
# You can directly access the config or the logger through the EasyAppHelper module
|
6
|
+
puts "The application verbose flag is #{EasyAppHelper.config[:verbose]}"
|
7
|
+
|
8
|
+
# You can directly use the logger according to the command line flags
|
9
|
+
# This will do nothing unless --debug is set and --log-level is set to the correct level
|
10
|
+
EasyAppHelper.logger.info "Hi guys!"
|
11
|
+
|
12
|
+
# Fed up with the EasyAppHelper prefix ? Just include the module where you want
|
13
|
+
include EasyAppHelper
|
14
|
+
|
15
|
+
# You can override programmatically any part of the config
|
16
|
+
config[:debug] = true
|
17
|
+
logger.level = 1
|
18
|
+
config[:test] = 'Groovy'
|
19
|
+
EasyAppHelper.logger.info "Hi guys!... again"
|
20
|
+
|
21
|
+
# You can see the internals of the config
|
22
|
+
puts config.internal_configs.to_yaml
|
23
|
+
# Which will output
|
24
|
+
#:modified:
|
25
|
+
# :content:
|
26
|
+
# :log-level: 1
|
27
|
+
# :debug: true
|
28
|
+
# :test: cool
|
29
|
+
# :source: Changed by code
|
30
|
+
#:command_line:
|
31
|
+
# :content:
|
32
|
+
# :auto:
|
33
|
+
# :simulate:
|
34
|
+
# :verbose: true
|
35
|
+
# :help:
|
36
|
+
# :config-file:
|
37
|
+
# :config-override:
|
38
|
+
# :debug:
|
39
|
+
# :debug-on-err:
|
40
|
+
# :log-level:
|
41
|
+
# :log-file:
|
42
|
+
# :source: Command line
|
43
|
+
#:system:
|
44
|
+
# :content: {}
|
45
|
+
# :source:
|
46
|
+
# :origin: EasyAppHelper
|
47
|
+
#:global:
|
48
|
+
# :content: {}
|
49
|
+
# :source:
|
50
|
+
# :origin: ''
|
51
|
+
#:user:
|
52
|
+
# :content: {}
|
53
|
+
# :source:
|
54
|
+
# :origin: ''
|
55
|
+
#:specific_file:
|
56
|
+
# :content: {}
|
57
|
+
|
58
|
+
# You see of course that the two modifications we did are in the modified sub-hash
|
59
|
+
# And now the merged config
|
60
|
+
puts config.to_hash
|
61
|
+
|
62
|
+
# But you can see the modified part as it is:
|
63
|
+
puts config.internal_configs[:modified]
|
64
|
+
|
65
|
+
# Of course you can access it from any class
|
66
|
+
class Dummy
|
67
|
+
include EasyAppHelper
|
68
|
+
|
69
|
+
def initialize
|
70
|
+
puts "#{config[:test]} baby !"
|
71
|
+
# Back to the original
|
72
|
+
config.reset
|
73
|
+
puts config.internal_configs[:modified]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
Dummy.new
|
78
|
+
|
79
|
+
# Some methods are provided to ease common tasks. For example this one will log at info level
|
80
|
+
# (so only displayed if debug mode and log level low enough), but will also puts on the console
|
81
|
+
# if verbose if set...
|
82
|
+
puts_and_logs "Hi world"
|
83
|
+
|
84
|
+
# It is actually one of the few methods added to regular Logger class (The added value of this logger
|
85
|
+
# is much more to be tightly coupled with the config object). Thus could access it like that:
|
86
|
+
logger.puts_and_logs "Hi world"
|
87
|
+
|
88
|
+
# or even
|
89
|
+
EasyAppHelper.logger.puts_and_logs "Hi world... 3 is enough."
|
90
|
+
|