easy_app_helper 2.0.2 → 2.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23d7222b6e27c900ec97f2f7a9883abbcae4e3a7
4
- data.tar.gz: 5c3958d362af194d4c44f74153093bc74074e9ed
3
+ metadata.gz: 53c79c3ab7f1d5d579b339daf801ddbf4075d52a
4
+ data.tar.gz: 1751310aea289a04187b81ea8234d3fce516d63b
5
5
  SHA512:
6
- metadata.gz: 42b3f9ce66bc4bb1cd0f633d83b9150b54bc907ea255e533d021be5835fd810b464ca5ebf85237601604174fed6ec7ca013fe07ab9478087cb123735de8b0b73
7
- data.tar.gz: 8c12f53068eb99052ca400241823a2ab1fb1c6cbfe6b35e7bb9c5b9c7cdbb594479d15eec83b52b6252aa8a8a833b2577d768c05d3064e34c9c9267480061f20
6
+ metadata.gz: 880f828c67d419ac672e9d04733b821f705dec3854e73625e6963ee662beebb6110317a02c821585f1748a23653d0195cf3efbae7df91ae8c51bdaab5ff121fb
7
+ data.tar.gz: a0099a111124742ff41ad1b9f594dd3eff987bdc35c1f6cf470d193ae3dc2dbd812a49ad9621d86560cdfb046f8d6a59df889f7f11a4ffdd2c94d4e1dcca56d7
data/README.md CHANGED
@@ -6,12 +6,13 @@ Every Ruby script on Earth has basically the same fundamental needs:
6
6
 
7
7
  * Config files everywhere accross the system, some of them belonging to the administrator some to the user
8
8
  running the application, some coming from the command line options and more...
9
- * Display a nice command-line help
9
+ * Support command line options directly overriding some of the properties defined in config files.
10
+ * Display a nice command-line options help
10
11
  * Logging stuff either to STDOUT, STDERR or to a specific log file.
11
12
 
12
- __If, like everyone, you have those basic needs, then this [gem][EAP] is definitely for you.__
13
+ __If, like everyone, you have those basic needs, then this [gem][EAH] is definitely for you.__
13
14
 
14
- This is a complete rewrite of the [easy_app_helper gem v1.x][EAP1] now based on the [stacked_config Gem][SC] for the
15
+ This is a complete rewrite of the [easy_app_helper gem v1.x][EAH1] now based on the [stacked_config Gem][SC] for the
15
16
  config file management part, but it maintains some compatibility with previous version. See
16
17
  [compatibility issues with previous versions](#compatibility-issues-with-previous-versions) for more information.
17
18
 
@@ -102,7 +103,7 @@ puts_and_logs 'Hello world'
102
103
  ### The command line options
103
104
 
104
105
  The command line options is one of the config layers maintained by the [stacked_config Gem][SC], and therefore there
105
- is not much to say except that [easy_app_helper][EAP] adds itself some options related to the logging as seen in the
106
+ is not much to say except that [easy_app_helper][EAH] adds itself some options related to the logging as seen in the
106
107
  [logger part](#the-logger).
107
108
 
108
109
  Of course as described in the [stacked_config Gem][SC] documentation, you can define your own options:
@@ -167,12 +168,87 @@ See [stacked_config Gem][SC] documentation for more options.
167
168
 
168
169
  ## Compatibility issues with previous versions
169
170
 
170
- [easy_app_helper][EAP] v2.x is not fully compatible with previous branch 1.x. But for common usage it should
171
+ [easy_app_helper][EAH] v2.x is not fully compatible with previous branch 1.x. But for common usage it should
171
172
  nevertheless be the case.
172
173
 
173
174
  There is a (not perfect) compatibility mode that you can trigger by setting the `easy_app_helper_compatibility_mode`
174
175
  property to true in one of your config files.
175
176
 
177
+ ## Complete example of a script based on `easy_app_helper`
178
+
179
+ Save the following file somewhere as `example.rb`.
180
+
181
+ You can use this as a template for your own scripts:
182
+
183
+ ```ruby
184
+ #!/usr/bin/env ruby
185
+
186
+ require 'easy_app_helper'
187
+
188
+ class MyApp
189
+
190
+ include EasyAppHelper
191
+
192
+ VERSION = '0.0.1'
193
+ NAME = 'My brand new Application'
194
+ DESCRIPTION = 'Best app ever'
195
+
196
+ def initialize
197
+ config.describes_application app_name: NAME,
198
+ app_version: VERSION,
199
+ app_description: DESCRIPTION
200
+ add_script_options
201
+ end
202
+
203
+ def add_script_options
204
+ config.add_command_line_section('Options for the script') do |slop|
205
+ slop.on :u, :useless, 'Stupid option', :argument => false
206
+ slop.on :an_int, 'Stupid option with integer argument', :argument => true, :as => Integer
207
+ end
208
+ end
209
+
210
+ def run
211
+ # An example of testing a command line option
212
+ config[:an_int] ||= 10
213
+
214
+ # Displaying command line help
215
+ if config[:help]
216
+ puts config.command_line_help
217
+ exit 0
218
+ end
219
+
220
+ begin
221
+ do_some_processing
222
+ rescue => e
223
+ puts "Program aborted with message: '#{e.message}'."
224
+ if config[:debug]
225
+ logger.fatal "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
226
+ else
227
+ puts ' Use --debug option for more detail.'
228
+ end
229
+ end
230
+ end
231
+
232
+ def do_some_processing
233
+ # Here you would really start your process
234
+ puts_and_logs 'Starting processing'
235
+ config[:something] = 'Added something...'
236
+
237
+ # When in debug mode, will log the config used by the application
238
+ logger.debug config[].to_yaml
239
+
240
+ if config[:verbose]
241
+ puts ' ## Here is a display of the config sources and contents'
242
+ puts config.detailed_layers_info
243
+ puts ' ## This the resulting merged config'
244
+ puts config[].to_yaml
245
+ end
246
+ end
247
+
248
+ end
249
+
250
+ MyApp.new.run
251
+ ```
176
252
 
177
253
  ## Contributing
178
254
 
@@ -186,6 +262,6 @@ property to true in one of your config files.
186
262
  __That's all folks.__
187
263
 
188
264
 
189
- [EAP]: https://rubygems.org/gems/easy_app_helper "EasyAppHelper gem"
190
- [EAP1]: https://rubygems.org/gems/easy_app_helper/tree/old_release_1_x "EasyAppHelper gem DEPRECATED branch"
265
+ [EAH]: https://rubygems.org/gems/easy_app_helper "EasyAppHelper gem"
266
+ [EAH1]: https://github.com/lbriais/easy_app_helper/tree/old_release_1_x "EasyAppHelper gem DEPRECATED branch"
191
267
  [SC]: https://github.com/lbriais/stacked_config "The stacked_config Gem"
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'pry'
24
24
  spec.add_development_dependency 'rspec', '~> 3.0'
25
25
 
26
- spec.add_runtime_dependency 'stacked_config', '~> 0.1', '>= 0.1.2'
26
+ spec.add_runtime_dependency 'stacked_config', '~> 0.1', '>= 0.1.3'
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module EasyAppHelper
2
- VERSION = '2.0.2'
2
+ VERSION = '2.0.3'
3
3
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  describe EasyAppHelper do
5
5
 
6
6
  %i(config logger puts_and_logs safely_exec).each do |m|
7
- it "should have module method #{m.to_s}" do
7
+ it "should have a :#{m.to_s} module method" do
8
8
  expect(subject).to respond_to m
9
9
  end
10
10
  end
@@ -18,7 +18,7 @@ describe EasyAppHelper do
18
18
  }
19
19
 
20
20
  %i(config logger puts_and_logs safely_exec).each do |m|
21
- it "should have a #{m.to_s} method " do
21
+ it "should have a :#{m.to_s} method " do
22
22
  expect(subject).to respond_to m
23
23
  end
24
24
 
data/spec/logger_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe EasyAppHelper.logger do
7
7
  expect(subject).to be_a_kind_of ::Logger
8
8
  end
9
9
 
10
- it 'should respond to puts_and_logs' do
10
+ it 'should respond to :puts_and_logs' do
11
11
  expect(subject).to respond_to :puts_and_logs
12
12
  end
13
13
 
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: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - L.Briais
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-26 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: '0.1'
76
76
  - - '>='
77
77
  - !ruby/object:Gem::Version
78
- version: 0.1.2
78
+ version: 0.1.3
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: '0.1'
86
86
  - - '>='
87
87
  - !ruby/object:Gem::Version
88
- version: 0.1.2
88
+ version: 0.1.3
89
89
  description: Easy Application Helpers framework
90
90
  email:
91
91
  - lbnetid+rb@gmail.com
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.0.0
136
+ rubygems_version: 2.0.14
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Provides cool helpers to your application, including configuration and logging