easy_app_helper 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,16 +24,15 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- To benefit from the different helpers. Once you installed the gem, the only thing you need to do is:
27
+ To benefit from the different helpers. Once you installed the gem, you just need to require it:
28
28
 
29
29
  ```ruby
30
30
  require 'easy_app_helper'
31
31
  ```
32
32
 
33
- and then in the "main class" of your application, include the modules you want to use and call init_app_helper in the initialize method. Then what you can do with each
34
- module is defined by each module.
33
+ And then in the "main class" of your application, include the modules you want to use and call init_app_helper in the initialize method. Then what you can do with each module is defined by each module itself.
35
34
 
36
- The basic behaviour (when you include EasyAppHelper), actually adds basic command line handling (actually handled by slop), and provides the mechanism to enable you to add any other EasyAppHelper module.
35
+ The basic behaviour (when you include EasyAppHelper), actually adds basic command line handling (actually handled by [Slop] [2]), and provides the mechanism to enable you to add any other EasyAppHelper module.
37
36
 
38
37
  ex:
39
38
 
@@ -41,10 +40,10 @@ ex:
41
40
  require 'easy_app_helper'
42
41
 
43
42
  class MyApp
44
- include EasyAppHelper
45
- def initialize
46
- init_app_helper "my_app"
47
- end
43
+ include EasyAppHelper
44
+ def initialize
45
+ init_app_helper "my_app"
46
+ end
48
47
  end
49
48
  ```
50
49
 
@@ -56,13 +55,13 @@ You could then do something like:
56
55
  require 'easy_app_helper'
57
56
 
58
57
  class MyApp
59
- include EasyAppHelper
60
- def initialize
61
- "my_app" init_app_helper "my_app", "My Super Application", "This is the application everybody was waiting for.", "v 1.0"
62
- if app_config[:verbose]
63
- puts "Waouh, hello World !!"
64
- end
65
- end
58
+ include EasyAppHelper
59
+ def initialize
60
+ init_app_helper "my_app", "My Super Application", "This is the application everybody was waiting for.", "1.0"
61
+ if app_config[:verbose]
62
+ puts "Waouh, hello World !!"
63
+ end
64
+ end
66
65
  end
67
66
  ```
68
67
 
@@ -76,10 +75,180 @@ Some other modules are provided:
76
75
 
77
76
  See [classes documentation] [3] for more information.
78
77
 
79
- ### Debugging
78
+ ### Complete example
79
+
80
+ Here under a more complete (still useless) example using all the modules.
81
+
82
+ ```ruby
83
+ require 'easy_app_helper'
84
+
85
+ class MyApp
86
+ include EasyAppHelper
87
+ include EasyAppHelper::Config
88
+ include EasyAppHelper::Logger
89
+
90
+ def initialize
91
+ init_app_helper "my_app", "My Super Application", "This is the application everybody was waiting for.", "1.0"
92
+ logger.info "Application is now started."
93
+ show_config if app_config[:verbose]
94
+ end
95
+
96
+ def show_config
97
+ puts "Application config is"
98
+ puts app_config.to_yaml
99
+ end
100
+
101
+ def add_specifc_command_line_options(opt)
102
+ opt.on :s, :stupid, 'This is a very stupid option', :argument => false
103
+ end
104
+ end
105
+
106
+ app = MyApp.new
107
+ ```
108
+
109
+ With this example you can already test some of the behaviours brought to the application by the different modules.
110
+
111
+ $ ruby ./test_app.rb
112
+
113
+ Nothing displayed... hum in fact normal.
114
+
115
+ *The EasyAppHelper::Base module*
116
+
117
+ $ ruby ./test_app.rb --verbose
118
+ Application config is
119
+ ---
120
+ :verbose: true
121
+ :log-level: 2
122
+
123
+ Here again we see the impact of the --verbose
124
+
125
+ $ ruby ./test_app.rb --help
126
+
127
+ Usage: my_app [options]
128
+ My Super Application Version: 1.0
129
+
130
+ This is the application everybody was waiting for.
131
+ -- Generic options -------------------------------------------
132
+ --auto Auto mode. Bypasses questions to user.
133
+ --simulate Do not perform the actual underlying actions.
134
+ -v, --verbose Enable verbose mode.
135
+ -h, --help Displays this help.
136
+
137
+ -- Debug and logging options ---------------------------------
138
+ --debug Run in debug mode.
139
+ --debug-on-err Run in debug mode with output to stderr.
140
+ --log-level Log level from 0 to 5, default 2.
141
+ --log-file File to log to.
142
+
143
+ -- Configuration options -------------------------------------
144
+ --config-file Specify a config file.
145
+
146
+ -- Script specific options------------------------------------
147
+ -s, --stupid This is a very stupid option
148
+
149
+
150
+ Here we see that:
151
+
152
+ * each included module added its own part in the global help
153
+ * The information passed to init_app_helper has been used in order to build a consistent help.
154
+ * The method implemented add_specifc_command_line_options did add the --stupid command line option and that it fits within the global help. the syntax is the [Slop] [2] syntax, and many other options are available. See the [Slop] [2] for further info.
155
+
156
+ *The EasyAppHelper::Debug module*
157
+
158
+ Now let's try some options related to the EasyAppHelper::Logger module
159
+
160
+ $ ruby ./test_app.rb --debug
161
+
162
+ Nothing is displayed. Why ? We used the logger.info stuff !! Just because the default log-level is 2 (Logger::Severity::WARN), whereas we did a info (Logger::Severity::INFO equals to 1).
163
+ Thus we can do a:
164
+
165
+ $ ruby ./test_app.rb --debug --log-level 1
166
+ I, [2013-03-20T10:58:40.819096 #13172] INFO -- : Application is now started.
167
+
168
+ Which correctly displays the log.
169
+ Of course, as mentioned by the inline doc, this could go to a log file using the --log-file option...
170
+
171
+ *The EasyAppHelper::Config module*
172
+
173
+ From what we did, nothing really shows what the config module brought to the application, whereas in fact this is the one bringing the more features...
174
+
175
+ This module will try to find config files (YAML format) in different places. All the config files could have a lot of different extensions (EasyAppHelper::Config::Instanciator::CONFIG_FILE_POSSIBLE_EXTENSIONS). Here under we will just say ".ext", but all of them are tried:
176
+
177
+ First it will try to find the file:
178
+
179
+ /etc/EasyAppHelper.ext
180
+
181
+ In this file you could define some options common to all the scripts you will build on top of EasyAppHelper helpers.
182
+
183
+ Then it will try to find (it will stop on the first found):
184
+
185
+ /etc/my_app.ext
186
+ /usr/local/etc/my_app.ext
187
+
188
+ In this file you could define some options common to all users
189
+
190
+ Then it will try to find:
191
+
192
+ ${HOME}/.config/my_app.conf
193
+
194
+ Where each user will generally store his own configuration.
195
+
196
+ Each of these file adds options to the common app_config hash. Enabling a simple and powerful override mechanism.
197
+
198
+ Then everything defined on the command line will itself override what has been defined in these config files.
199
+ Then if --config-file option is specified in the command line, it tries to load that file.
200
+
201
+ Thus in the end following mechanism:
202
+
203
+ admin wide -> system wide -> user -> command line options -> --config-file
204
+
205
+
206
+ ### Debugging the framework itself
80
207
 
81
208
  If you want to debug what happens during the framework instanciation, you can use the DEBUG_EASY_MODULES environment variable.
82
209
 
210
+ ex:
211
+
212
+ $ DEBUG_EASY_MODULES=y ruby ./test_app.rb
213
+ D, [2013-03-20T13:14:32.149109 #10564] DEBUG -- : Processing helper module: EasyAppHelper::Logger::Instanciator
214
+ D, [2013-03-20T13:14:32.149109 #10564] DEBUG -- : Processing helper module: EasyAppHelper::Config::Instanciator
215
+ D, [2013-03-20T13:14:32.149109 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.conf" as config file.
216
+ D, [2013-03-20T13:14:32.149109 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.yml" as config file.
217
+ D, [2013-03-20T13:14:32.149109 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.cfg" as config file.
218
+ D, [2013-03-20T13:14:32.149109 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.yaml" as config file.
219
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.CFG" as config file.
220
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.YML" as config file.
221
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.YAML" as config file.
222
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/EasyAppHelper.Yaml" as config file.
223
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.conf" as config file.
224
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.yml" as config file.
225
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.cfg" as config file.
226
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.yaml" as config file.
227
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.CFG" as config file.
228
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.YML" as config file.
229
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.YAML" as config file.
230
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/etc/my_app.Yaml" as config file.
231
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.conf" as config file.
232
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.yml" as config file.
233
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.cfg" as config file.
234
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.yaml" as config file.
235
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.CFG" as config file.
236
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.YML" as config file.
237
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.YAML" as config file.
238
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/usr/local/etc/my_app.Yaml" as config file.
239
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.conf" as config file.
240
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.yml" as config file.
241
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.cfg" as config file.
242
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.yaml" as config file.
243
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.CFG" as config file.
244
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.YML" as config file.
245
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.YAML" as config file.
246
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Trying "/home/user_home_dir/.config/my_app.Yaml" as config file.
247
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Processing helper module: EasyAppHelper::Base::Instanciator
248
+ D, [2013-03-20T13:14:32.164733 #10564] DEBUG -- : Processing helper module: EasyAppHelper::Common::Instanciator
249
+
250
+ You can observe that for each included module, the framwork uses its related so-called instanciator in order to know how to start the module, externalizing the methods into a separated module to avoid poluting your own application with methods useless for you when you include the module.
251
+
83
252
  ## Contributing
84
253
 
85
254
  1. Fork it
@@ -94,17 +94,17 @@ module EasyAppHelper::Config::Instanciator
94
94
 
95
95
  # Reads config from admin config file.
96
96
  def self.load_admin_wide_config(app)
97
- load_config_file app, find_file(ADMIN_CONFIG_POSSIBLE_PLACES, ADMIN_CONFIG_FILENAME)
97
+ load_config_file app, find_file(app, ADMIN_CONFIG_POSSIBLE_PLACES, ADMIN_CONFIG_FILENAME)
98
98
  end
99
99
 
100
100
  # Reads config from system config file.
101
101
  def self.load_system_wide_config(app, script_filename)
102
- load_config_file app, find_file(SYSTEM_CONFIG_POSSIBLE_PLACES, script_filename)
102
+ load_config_file app, find_file(app, SYSTEM_CONFIG_POSSIBLE_PLACES, script_filename)
103
103
  end
104
104
 
105
105
  # Reads config from user config file.
106
106
  def self.load_user_config(app, script_filename)
107
- load_config_file app, find_file(USER_CONFIG_POSSIBLE_PLACES, script_filename)
107
+ load_config_file app, find_file(app, USER_CONFIG_POSSIBLE_PLACES, script_filename)
108
108
  end
109
109
 
110
110
  # Loads a config file.
@@ -122,12 +122,14 @@ module EasyAppHelper::Config::Instanciator
122
122
  end
123
123
 
124
124
  # Tries to find config files according to places (array) given and possible extensions
125
- def self.find_file(places, filename)
125
+ def self.find_file(app, places, filename)
126
126
  places.each do |dir|
127
127
  CONFIG_FILE_POSSIBLE_EXTENSIONS.each do |ext|
128
128
  filename_with_path = dir + '/' + filename + '.' + ext
129
129
  if File.exists? filename_with_path
130
130
  return filename_with_path
131
+ else
132
+ app.logger.debug "Trying \"#{filename_with_path}\" as config file."
131
133
  end
132
134
  end
133
135
  end
@@ -87,7 +87,7 @@ module EasyAppHelper::Logger::Instanciator
87
87
  slop_definition.separator "\n-- Debug and logging options ---------------------------------"
88
88
  slop_definition.on :debug, 'Run in debug mode.', :argument => false
89
89
  slop_definition.on 'debug-on-err', 'Run in debug mode with output to stderr.', :argument => false
90
- slop_definition.on 'log-level', "Log level from 0 to 5, default #{Logger::Severity::ERROR}.", :argument => true, :as => Integer
90
+ slop_definition.on 'log-level', "Log level from 0 to 5, default #{EasyAppHelper::Common::DEFAULT_LOG_LEVEL}.", :argument => true, :as => Integer
91
91
  slop_definition.on 'log-file', 'File to log to.', :argument => true
92
92
  end
93
93
 
@@ -6,5 +6,5 @@
6
6
  ################################################################################
7
7
 
8
8
  module EasyAppHelper
9
- VERSION = "0.0.6"
9
+ VERSION = "0.0.7"
10
10
  end
metadata CHANGED
@@ -1,69 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_app_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - L.Briais
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-19 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: pry
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: slop
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - '>='
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - '>='
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0'
69
78
  description: Easy Application Helpers framework
@@ -88,26 +97,28 @@ files:
88
97
  homepage: https://github.com/lbriais/easy_app_helper
89
98
  licenses:
90
99
  - MIT
91
- metadata: {}
92
100
  post_install_message:
93
101
  rdoc_options: []
94
102
  require_paths:
95
103
  - lib
96
104
  required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
97
106
  requirements:
98
- - - '>='
107
+ - - ! '>='
99
108
  - !ruby/object:Gem::Version
100
109
  version: '0'
101
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
102
112
  requirements:
103
- - - '>='
113
+ - - ! '>='
104
114
  - !ruby/object:Gem::Version
105
115
  version: '0'
106
116
  requirements: []
107
117
  rubyforge_project:
108
- rubygems_version: 2.0.0.rc.2
118
+ rubygems_version: 1.8.25
109
119
  signing_key:
110
- specification_version: 4
120
+ specification_version: 3
111
121
  summary: Provides cool helpers to your application, including configuration and logging
112
122
  features
113
123
  test_files: []
124
+ has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 50d87ed053be2fd95061ffa2437b85d54624733d
4
- data.tar.gz: 49c874b9d20f77fbd39dd0b1e85dfe3ac6b59dd5
5
- SHA512:
6
- metadata.gz: 07a81b4154ce7c2325d64b7d471063e458fca4d14e161fa97ad612523dad0475b85dbb3d7e5988ce3136d6cacaea3b09c860bb81ef87daf67d480d121201b72d
7
- data.tar.gz: 2b2d0d30cd08aa7d3e6a1d847734d2c60937b653d39f5498289e8e98dc9a07a0768bfd84066f205b996699126b5c70ba0d8c68cfb955e6dab6456e34f5e943bc