easy_app_helper 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0584c63fd15bf478ad92e3ef47a46bbd1fa1605f
4
- data.tar.gz: 3831a40b67f1e89390180a82310cf0bc0e414849
3
+ metadata.gz: 977d7804e7e46cd53b44ea5587f02f3f6a085eb1
4
+ data.tar.gz: 0cd1dca9156798a14d84e679e3db53dd5025212b
5
5
  SHA512:
6
- metadata.gz: 5adc276768419c22019d6efa06b3a6f904d3371fcf00a0d8f27b59577b9695249540255eebbf7975e48ab31447dffc2cdd8844755024c386dc3ebdc8150bf606
7
- data.tar.gz: f154759d2d1a54d9d58157c17930af7284a9ef4a0aacc4322fa6817c499629dffe5ba2b52d7f5008e0f93ecfac7c9299085289fa6d9dc62d398f514b137f4f64
6
+ metadata.gz: c0f6a267e9155055177284f6790216f519e74fc7c7da221d368f33384eea2f3248f0eb5617bd14400b7b770a1dcdeca77092efde60fd7b4c85c00a57ddad6cd9
7
+ data.tar.gz: 86d147b433243fa30559029539cdfd47d0b56d0b36dcfaf8784f2f1c830d65923b35a36285b0eaa39a8ad1f51729c3d9794f1a84454df1a2a7e552a093851c98
data/README.md CHANGED
@@ -181,6 +181,23 @@ regarding the rules described above, the framework will for the following files
181
181
  /etc/EasyAppHelper.Yaml
182
182
  ```
183
183
 
184
+ ### Internal config file
185
+
186
+ This is an internal config file for the Gem itself. It will be located in the etc directory **inside** the Gem.
187
+
188
+ ```text
189
+ # The :internal layer
190
+ etc/myscript.conf
191
+ etc/myscript.yml
192
+ etc/myscript.cfg
193
+ etc/myscript.yaml
194
+ etc/myscript.CFG
195
+ etc/myscript.YML
196
+ etc/myscript.YAML
197
+ etc/myscript.Yaml
198
+ ```
199
+
200
+
184
201
  ### Application config files
185
202
 
186
203
  Application config file names are determined from the config.script_filename property. It initially contains
@@ -224,7 +241,7 @@ ${HOME}/.config/myscript.Yaml
224
241
  ### Command line specified config file
225
242
 
226
243
  The command line option ```--config-file``` provides a way to specify explicitly a config file. On top of this the
227
- option ```--config-override``` tells **EasyAppHelper** to ignore :system, :global and :user levels.
244
+ option ```--config-override``` tells **EasyAppHelper** to ignore :system, :internal, :global and :user levels.
228
245
 
229
246
  The file will be loaded in a separated layer called :specific_file
230
247
 
@@ -455,6 +472,10 @@ D, [2013-06-23T19:43:47.981934 #16294] DEBUG -- : Config layers:
455
472
  :copyright: (c) 2012-2013 Nanonet
456
473
  :source: /etc/EasyAppHelper.cfg
457
474
  :origin: EasyAppHelper
475
+ :internal:
476
+ :content: {}
477
+ :source:
478
+ :origin: test4_app
458
479
  :global:
459
480
  :content: {}
460
481
  :source:
@@ -13,9 +13,9 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/lbriais/easy_app_helper"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = `git ls-files`.split($/).delete_if { |file| file =~ /^(bin|\.)/ or file =~ /test\d*_app\.rb$/ }
17
+ # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features|etc)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler"
@@ -0,0 +1,3 @@
1
+ # This file is used for test only and should not be deployed with the Gem
2
+
3
+ internal_credits: The EasyAppHelper Gem
@@ -13,6 +13,7 @@ require 'slop'
13
13
 
14
14
  class EasyAppHelper::Core::Base
15
15
  CHANGED_BY_CODE = 'Changed by code'
16
+ INTRODUCED_SORTED_LAYERS = [:modified, :command_line]
16
17
 
17
18
  attr_reader :script_filename, :app_name, :app_version, :app_description, :internal_configs, :logger
18
19
 
@@ -91,6 +92,35 @@ class EasyAppHelper::Core::Base
91
92
  self
92
93
  end
93
94
 
95
+ # Convenient method to set a value in a particular layer
96
+ # If the layer does not exist it is correctly created and filled in with the key/value couple
97
+ def set_value key, value, layer = nil
98
+ if layer.nil?
99
+ self[key] = value
100
+ return
101
+ end
102
+ unless layers.include? layer
103
+ internal_configs[layer] = {content: {}, source: 'Unknown source'}
104
+ logger.warn "Trying to modify a non existing config layer: \"#{layer.to_s}\". Automatically creating it..."
105
+ end
106
+ internal_configs[layer][:content][key] = value
107
+ end
108
+
109
+ def get_value key, layer = nil
110
+ if layer.nil?
111
+ return self[key]
112
+ end
113
+ res = nil
114
+ begin
115
+ res = internal_configs[layer][:content][key]
116
+ rescue => e
117
+ logger.warn "Trying to reading from a non existing config layer: \"#{layer}\". Returning nil for the key \"#{key}\"..."
118
+ end
119
+ res
120
+ end
121
+
122
+
123
+
94
124
  # Any modification done to the config is in fact stored in the :modified layer of internal_configs
95
125
  # @param [String] key
96
126
  # @param [String] value
@@ -107,11 +137,27 @@ class EasyAppHelper::Core::Base
107
137
 
108
138
  # @return [Array] List of layers
109
139
  def layers
110
- internal_configs.keys
140
+ res = self.class.layers
141
+ internal_configs.keys.each do |layer|
142
+ next if res.include? layer
143
+ res << layer
144
+ end
145
+ res
111
146
  end
112
147
 
148
+ def self.layers
149
+ res = []
150
+ self.ancestors.each do |klass|
151
+ next unless klass.is_a? Class
152
+ break if EasyAppHelper::Core::Base < klass
153
+ res << klass::INTRODUCED_SORTED_LAYERS.reverse
154
+ end
155
+ res.flatten.reverse
156
+ end
157
+
158
+
113
159
  def find_layer(key)
114
- [:modified, :command_line].each do |layer|
160
+ layers.each do |layer|
115
161
  return layer if internal_configs[layer][:content][key]
116
162
  end
117
163
  nil
@@ -149,7 +195,7 @@ class EasyAppHelper::Core::Base
149
195
  when :'log-level'
150
196
  logger.send :level=, value, false
151
197
  when :'config-file'
152
- internal_configs[layer][:content][key] = value
198
+ set_value key, value, layer
153
199
  force_reload
154
200
  processed = true
155
201
  end
@@ -45,6 +45,7 @@ class EasyAppHelper::Core::Config
45
45
  include EasyAppHelper::Core::Config::Places.get_os_module
46
46
 
47
47
  ADMIN_CONFIG_FILENAME = EasyAppHelper.name
48
+ INTRODUCED_SORTED_LAYERS = [:specific_file, :user, :global, :internal, :system]
48
49
 
49
50
  # Potential extensions a config file can have
50
51
  CONFIG_FILE_POSSIBLE_EXTENSIONS = %w(conf yml cfg yaml CFG YML YAML Yaml)
@@ -80,6 +81,7 @@ class EasyAppHelper::Core::Config
80
81
  def load_config(force=false)
81
82
  super()
82
83
  load_layer_config :system, ADMIN_CONFIG_FILENAME, force
84
+ load_layer_config :internal, script_filename, force
83
85
  load_layer_config :global, script_filename, force
84
86
  load_layer_config :user, script_filename, force
85
87
  load_layer_config :specific_file, internal_configs[:command_line][:content][:'config-file'], force
@@ -98,19 +100,32 @@ class EasyAppHelper::Core::Config
98
100
  # using {#internal_configs}), while this methods provides a merged config.
99
101
  # @return [Hash] The hash of the merged config.
100
102
  def to_hash
101
- merged_config = [:system, :global, :user].inject({}) do |temp_config, config_level|
103
+
104
+ merged_config = {}
105
+
106
+ # Process any other level as a low priority unmanaged layer
107
+ internal_configs.keys.each do |layer|
108
+ next if self.class.layers.include? layer
109
+ hashes_second_level_merge merged_config, internal_configs[layer][:content]
110
+ end
111
+
112
+ # Process Config-level layers
113
+ merged_config = [:system, :internal, :global, :user].inject(merged_config) do |temp_config, config_level|
102
114
  hashes_second_level_merge temp_config, internal_configs[config_level][:content]
103
115
  end
104
- if internal_configs[:command_line][:content][:'config-file']
105
- if internal_configs[:command_line][:content][:'config-override']
116
+ if get_value :'config-file', :command_line
117
+ if get_value :'config-override', :command_line
106
118
  override_merge merged_config, internal_configs[:specific_file][:content]
107
119
  else
108
120
  hashes_second_level_merge merged_config, internal_configs[:specific_file][:content]
109
121
  end
110
122
 
111
123
  end
112
- hashes_second_level_merge merged_config, internal_configs[:command_line][:content]
113
- hashes_second_level_merge merged_config, internal_configs[:modified][:content]
124
+
125
+ # Process Base-level layers with highest priority (last processed the highest)
126
+ [:command_line, :modified].each { |base_layer| hashes_second_level_merge merged_config, internal_configs[base_layer][:content]}
127
+ merged_config
128
+
114
129
  end
115
130
 
116
131
  # @param [Object] key: The key to access the data in the merged_config hash (see {#to_hash})
@@ -125,15 +140,8 @@ class EasyAppHelper::Core::Config
125
140
  to_hash.to_yaml
126
141
  end
127
142
 
128
- def find_layer(key)
129
- layer = super
130
- return layer unless layer.nil?
131
- [:specific_file, :user, :global, :system].each do |layer|
132
- return layer if internal_configs[layer][:content][key]
133
- end
134
- nil
135
- end
136
-
143
+ alias_method :to_s, :to_yaml
144
+ alias_method :inspect, :internal_configs
137
145
 
138
146
  #############################################################################
139
147
  private
@@ -8,11 +8,25 @@
8
8
  # Possible places regarding the OS
9
9
  # TODO: Add equivalent for Mac
10
10
  class EasyAppHelper::Core::Config::Places
11
+
12
+ module Helper
13
+
14
+ def get_internal_config_place
15
+ File.expand_path('../../etc', $PROGRAM_NAME)
16
+ end
17
+
18
+ end
19
+
20
+
11
21
  module Unix
12
22
  # Where could be stored admin configuration that rules all EasyAppHelper
13
23
  # based applications.
24
+ extend Helper
25
+
14
26
  POSSIBLE_PLACES = {
15
27
 
28
+ internal: ["#{self.get_internal_config_place}"],
29
+
16
30
  system: ["/etc"],
17
31
 
18
32
  # Where could be stored global wide configuration
@@ -27,8 +41,12 @@ class EasyAppHelper::Core::Config::Places
27
41
  module Windows
28
42
  # Where could be stored admin configuration that rules all EasyAppHelper
29
43
  # based applications.
44
+ extend Helper
45
+
30
46
  POSSIBLE_PLACES = {
31
47
 
48
+ internal: ["#{self.get_internal_config_place}"],
49
+
32
50
  system: ["#{ENV['systemRoot']}/Config"],
33
51
 
34
52
  # Where could be stored global configuration
@@ -46,6 +64,7 @@ class EasyAppHelper::Core::Config::Places
46
64
  }
47
65
  DEFAULT = Unix
48
66
 
67
+
49
68
  def self.get_os_module
50
69
  conf = CONF[RbConfig::CONFIG['target_os'].to_sym]
51
70
  conf.nil? ? DEFAULT : conf
@@ -6,5 +6,5 @@
6
6
  ################################################################################
7
7
 
8
8
  module EasyAppHelper
9
- EASY_APP_HELPER_VERSION = "1.0.6"
9
+ EASY_APP_HELPER_VERSION = "1.0.7"
10
10
  end
data/spec/config_spec.rb CHANGED
@@ -10,8 +10,9 @@ require 'easy_app_helper'
10
10
 
11
11
 
12
12
  #describe EasyAppHelper::Core::Config do
13
- describe EasyAppHelper.config do
14
- SAMPLE_STRING = 'Sample String'
13
+ describe "The EasyAppHelper config object" do
14
+ SAMPLE_STRING = 'TestConfig'
15
+ subject {EasyAppHelper.config}
15
16
 
16
17
 
17
18
  it 'should be fully initialized when first accessed' do
@@ -19,13 +20,12 @@ describe EasyAppHelper.config do
19
20
  subject.logger.should_not be nil
20
21
  end
21
22
 
22
- it 'should be consistent regarding the way it is accessed' do
23
+ it 'should be consistent regardless the way it is accessed' do
23
24
  subject[:basic_test] = SAMPLE_STRING
24
25
  expect(subject[]).to eq subject.to_hash
25
26
  expect(subject[:basic_test]).to eq SAMPLE_STRING
26
27
  end
27
28
 
28
-
29
29
  it 'should be the same object accross different instances' do
30
30
  expect(subject[:basic_test]).to eq SAMPLE_STRING
31
31
  end
@@ -33,11 +33,10 @@ describe EasyAppHelper.config do
33
33
  it 'should store the data in the :modified layer' do
34
34
  expect(subject.find_layer :basic_test).to eq :modified
35
35
  expect(subject.internal_configs[:modified][:content][:basic_test]).to eq subject[:basic_test]
36
-
37
36
  end
38
37
 
39
38
  it 'should provide a direct r/w access to layers' do
40
- subject.internal_configs[:system][:content][:stupid_conf] = SAMPLE_STRING
39
+ subject.set_value :stupid_conf, SAMPLE_STRING, :system
41
40
  expect(subject[:stupid_conf]).to eq SAMPLE_STRING
42
41
  end
43
42
 
@@ -52,21 +51,23 @@ describe EasyAppHelper.config do
52
51
  end
53
52
 
54
53
 
55
- describe 'should override data when present in multiple layers' do
54
+ context 'when dealing with the multiple layers of the config' do
55
+
56
56
  before(:all) do
57
57
  EasyAppHelper.config.layers.each do |layer|
58
- EasyAppHelper.config.internal_configs[layer][:content][:basic_test] = "#{SAMPLE_STRING} #{layer.to_s}"
58
+ EasyAppHelper.config.set_value :basic_test, "#{SAMPLE_STRING} #{layer.to_s}", layer
59
59
  end
60
- EasyAppHelper.config.internal_configs[:command_line][:content][:'config-file'] = true
60
+ EasyAppHelper.config.set_value :'config-file', true, :command_line
61
61
  end
62
62
 
63
- context "when requesting some data" do
64
- let(:layers) {[:modified, :command_line, :specific_file, :user, :global, :system]}
63
+ context "when trying to access some data" do
64
+ let(:layers) {subject.layers}
65
+ #subject {EasyAppHelper.config}
65
66
 
66
- original_ordered_layers = [:modified, :command_line, :specific_file, :user, :global, :system]
67
+ original_ordered_layers = EasyAppHelper.config.layers
67
68
  layers = original_ordered_layers.dup
68
69
  original_ordered_layers.each do |layer|
69
- test_descr = "should find the data in #{layer} layer if present in #{layer} layer"
70
+ test_descr = "It should find the data in #{layer} layer if present in #{layer} layer"
70
71
  unless layers.length == original_ordered_layers.length
71
72
  already_removed = original_ordered_layers - layers
72
73
  if already_removed.length == 1
@@ -89,6 +90,37 @@ describe EasyAppHelper.config do
89
90
  end
90
91
  end
91
92
 
93
+ context "when accessing a non existing layer" do
94
+ context "in read mode" do
95
+
96
+ it "should log a warning and return nil" do
97
+ subject.logger.should_receive(:warn)
98
+ expect(subject.get_value :non_existing_value, :another_non_existing_layer).to be_nil
99
+ end
100
+ end
101
+
102
+ context "in write mode" do
103
+
104
+ it "should log a warning and create it" do
105
+ subject.logger.should_receive(:warn)
106
+ subject.set_value :non_existing_value, SAMPLE_STRING, :another_non_existing_layer
107
+ expect(subject.get_value :non_existing_value, :another_non_existing_layer).to be SAMPLE_STRING
108
+ expect(subject[:non_existing_value]).to be SAMPLE_STRING
109
+ end
110
+ end
111
+ end
112
+
113
+ context "when manually creating a layer" do
114
+
115
+ it "should be handled with the lowest priority" do
116
+ subject.set_value :unused_option, SAMPLE_STRING, :non_existing_layer
117
+ expect(subject[:unused_option]).to eq SAMPLE_STRING
118
+ subject.set_value :unused_option, 'Not the sample string', :system
119
+ expect(subject[:unused_option]).to_not eq SAMPLE_STRING
120
+ end
121
+
122
+ end
123
+
92
124
  end
93
125
 
94
126
  context "when reset" do
@@ -100,9 +132,9 @@ describe EasyAppHelper.config do
100
132
  end
101
133
 
102
134
  it "should keep modifications directly done on internal layers" do
103
- subject.internal_configs[:system][:content][:stupid_conf] = SAMPLE_STRING
135
+ subject.set_value :stupid_conf, SAMPLE_STRING, :system
104
136
  subject.reset
105
- expect(subject.internal_configs[:system][:content][:stupid_conf]).to eq SAMPLE_STRING
137
+ expect(subject.get_value :stupid_conf, :system).to eq SAMPLE_STRING
106
138
  end
107
139
 
108
140
  end
@@ -116,11 +148,11 @@ describe EasyAppHelper.config do
116
148
  end
117
149
 
118
150
  it "should remove all modifications directly done on internal layers" do
119
- subject.internal_configs[:system][:content][:stupid_conf] = SAMPLE_STRING
120
- subject.internal_configs[:command_line][:content][:stupid_conf] = SAMPLE_STRING
151
+ subject.set_value :stupid_conf, SAMPLE_STRING, :system
152
+ subject.set_value :stupid_conf, SAMPLE_STRING, :command_line
121
153
  subject.load_config
122
- expect(subject.internal_configs[:system][:content][:stupid_conf]).to be_nil
123
- expect(subject.internal_configs[:command_line][:content][:stupid_conf]).to be_nil
154
+ expect(subject.get_value :stupid_conf,:system).to be_nil
155
+ expect(subject.get_value :stupid_conf,:command_line).to be_nil
124
156
  end
125
157
 
126
158
  end
@@ -134,11 +166,11 @@ describe EasyAppHelper.config do
134
166
  end
135
167
 
136
168
  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
169
+ subject.set_value :stupid_conf, SAMPLE_STRING, :system
170
+ subject.set_value :stupid_conf, SAMPLE_STRING, :command_line
139
171
  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
172
+ expect(subject.get_value :stupid_conf,:system).to be_nil
173
+ expect(subject.get_value :stupid_conf,:command_line).to be_nil
142
174
  end
143
175
 
144
176
  end
@@ -155,4 +187,15 @@ describe EasyAppHelper.config do
155
187
 
156
188
  end
157
189
 
190
+ context "When a gem has its own :internal config file" do
191
+ before(:all) do
192
+ EasyAppHelper.config.script_filename = "test_internal"
193
+ end
194
+
195
+ it "should take its data in account" do
196
+ expect(subject[:internal_credits]).to_not be_nil
197
+ end
198
+
199
+ end
200
+
158
201
  end
data/spec/logger_spec.rb CHANGED
@@ -10,19 +10,20 @@ require 'easy_app_helper'
10
10
 
11
11
 
12
12
  #describe EasyAppHelper::Core::Logger
13
- describe EasyAppHelper.logger do
13
+ describe "The EasyAppHelper logger object" do
14
+ subject {EasyAppHelper.logger}
14
15
  let (:config) {EasyAppHelper.config}
15
16
 
16
- context "to modify the log level" do
17
+ context "to modify the log level, it should be possible " do
17
18
 
18
- it 'should be ok to use the config object' do
19
+ it 'to use the config object' do
19
20
  Logger::Severity::DEBUG.upto(Logger::Severity::UNKNOWN) do |severity|
20
21
  config[:'log-level'] = severity
21
22
  expect(subject.level).to eq severity
22
23
  end
23
24
  end
24
25
 
25
- it 'should be ok to use the #log_level= method' do
26
+ it 'or directly the #log_level= method of the logger object' do
26
27
  Logger::Severity::DEBUG.upto(Logger::Severity::UNKNOWN) do |severity|
27
28
  subject.level= severity
28
29
  expect(config[:'log-level']).to eq severity
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.6
4
+ version: 1.0.7
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-08-28 00:00:00.000000000 Z
11
+ date: 2013-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,13 +87,12 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .travis.yml
92
90
  - Gemfile
93
91
  - LICENSE.txt
94
92
  - README.md
95
93
  - Rakefile
96
94
  - easy_app_helper.gemspec
95
+ - etc/test_internal.conf
97
96
  - lib/easy_app_helper.rb
98
97
  - lib/easy_app_helper/core/base.rb
99
98
  - lib/easy_app_helper/core/config.rb
@@ -105,10 +104,6 @@ files:
105
104
  - spec/config_spec.rb
106
105
  - spec/logger_spec.rb
107
106
  - test/test.yml
108
- - test/test2_app.rb
109
- - test/test3_app.rb
110
- - test/test4_app.rb
111
- - test/test_app.rb
112
107
  homepage: https://github.com/lbriais/easy_app_helper
113
108
  licenses:
114
109
  - MIT
@@ -135,11 +130,8 @@ specification_version: 4
135
130
  summary: Provides cool helpers to your application, including configuration and logging
136
131
  features
137
132
  test_files:
133
+ - etc/test_internal.conf
138
134
  - spec/config_spec.rb
139
135
  - spec/logger_spec.rb
140
136
  - test/test.yml
141
- - test/test2_app.rb
142
- - test/test3_app.rb
143
- - test/test4_app.rb
144
- - test/test_app.rb
145
137
  has_rdoc:
data/.gitignore DELETED
@@ -1,48 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- /pkg/
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
19
- # Standard
20
- *~
21
- # Standard Rails project
22
- /tmp/
23
- /log/
24
- /db/*.sqlite3
25
- # SASS CSS generation
26
- /public/stylesheets/.sass-cache/
27
- # Netbeans
28
- /nbproject/
29
- # Sublime Text 2 project
30
- *.sublime-project
31
- *.sublime-workspace
32
- *(copie)*
33
- # RVM
34
- .rvmrc
35
- # VisualRuby
36
- .vr_settings.yaml
37
- # Emacs
38
- *#
39
- *\#
40
- \#*
41
- .#*
42
- \#*\#
43
- # Geany
44
- *.geany
45
- # RubyMine
46
- .idea
47
- #RedCar
48
- .redcar
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- script:
5
- - bundle exec rake spec
data/test/test2_app.rb DELETED
@@ -1,33 +0,0 @@
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 DELETED
@@ -1,90 +0,0 @@
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
-
data/test/test4_app.rb DELETED
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'easy_app_helper'
4
-
5
- class MyApp
6
- include EasyAppHelper
7
-
8
- APP_NAME = "My super application"
9
- # SCRIPT_NAME = File.basename($0, '.*')
10
- VERSION = '0.0.1'
11
- DESCRIPTION = 'This application is a proof of concept for EasyAppHelper.'
12
-
13
-
14
- def initialize
15
- # Providing this data is optional
16
- config.describes_application(app_name: APP_NAME, app_version: VERSION, app_description: DESCRIPTION)
17
- end
18
-
19
-
20
- def run
21
- if config[:help]
22
- puts config.help
23
- exit 0
24
- end
25
- puts_and_logs "Application is starting"
26
- do_some_processing
27
- end
28
-
29
- def do_some_processing
30
- puts_and_logs "Starting some heavy processing"
31
- end
32
-
33
- end
34
-
35
-
36
- MyApp.new.run
data/test/test_app.rb DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
-
4
- require 'easy_app_helper'
5
-
6
-
7
- class Pipo
8
- include EasyAppHelper
9
-
10
-
11
- def toto
12
- puts_and_logs "Now from a second class"
13
- puts_and_logs config.to_hash
14
- end
15
- end
16
-
17
-
18
-
19
- class TestApp
20
- include EasyAppHelper
21
-
22
- def initialize
23
- #config.script_filename = File.basename $0
24
- config.app_name = 'Test application'
25
- #config.app_description = 'Best app to test the framework'
26
- #config.app_version = '1.0.0'
27
- puts_and_logs "Hello World"
28
- p = Pipo.new.toto
29
- config.script_filename = 'batch_audio_convert'
30
- puts config.to_hash
31
- config.internal_configs.each do |layer|
32
- puts layer
33
- end
34
- add_cmd_line_options
35
- puts config.help
36
- logger.error "INTARG: #{config[:intarg]}"
37
-
38
- # puts config.help
39
- end
40
-
41
- def add_cmd_line_options
42
- config.add_command_line_section do |slop|
43
- slop.on :u, :useless, 'Stupid option', :argument => false
44
- slop.on :anint, 'Stupid option with integer argument', :argument => true, :as => Integer
45
- end
46
- end
47
-
48
- end
49
-
50
- t = TestApp.new
51
- include EasyAppHelper
52
- logger.warn "Yeah"
53
- EasyAppHelper.logger.error "Groovy baby !"
54
- puts_and_logs "Hey man"
55
- #puts config.inspect
56
- puts "bye"