easy_app_helper 1.0.4 → 1.0.5

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: cc54e601367ad38a97f650c2a3e1459a9a67b2ca
4
- data.tar.gz: 47bbac78490b6c347d9bd21e4845c87e023fb8fc
3
+ metadata.gz: 7ecbc48dfd4704a478842023bb560f06c271bf05
4
+ data.tar.gz: 903c92b33e0a73983a1be10634fb15c24e506d89
5
5
  SHA512:
6
- metadata.gz: 4886fb5031204dd4752962ec429f50c86cc8d4a6f81c9791de5303c9a2255ca6f0ce7926405a53ce160b775ba8fc924132d8d3c22354351e212869d6d1cd62ef
7
- data.tar.gz: 22e6eea0d5239e883867c5d1c1c0c220b3cef8f5a53b5a55084b3ba137f67139bc65a41c44885ea86b70e71e44aefd9f597c7ed31caf8803a95274ba0eccd69b
6
+ metadata.gz: cde655e0c910beddfd6708ab94072d766e09094dc0d8d24f0dfe887f56dee45e1277ca5d78321f7385cf6c2270eefc224e091d7fc868a0b251c7ad4dd0d475c9
7
+ data.tar.gz: 86f57ebfa4d5046977f0e392b43239630e09189f1e79422c13dfae6bfd15abf0f8ee0d6b463cc556c75a8f977e3ccc0dd5ba6035b1de936861c53345551fa570
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script:
5
+ - bundle exec rake spec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 TODO: Write your name
1
+ Copyright (c) 2013 L.Briais
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # EasyAppHelper
2
2
 
3
+ [![Build Status](https://travis-ci.org/lbriais/easy_app_helper.png?branch=master)](https://travis-ci.org/lbriais/easy_app_helper)
4
+ [![Gem Version](https://badge.fury.io/rb/easy_app_helper.png)](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 two modifications we did are in the modified sub-hash
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
 
@@ -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|rspec|features)/})
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.get_OS_module
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? ? self.to_hash : self.to_hash[key]
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 handing_over_to(log)
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
- handing_over_to config[:'log-file']
61
+ hand_over_to config[:'log-file']
62
62
  elsif config[:"debug-on-err"]
63
- handing_over_to STDERR
63
+ hand_over_to STDERR
64
64
  else
65
- handing_over_to STDOUT
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: ['C:/Windows/Config',
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.get_OS_module
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
@@ -6,5 +6,5 @@
6
6
  ################################################################################
7
7
 
8
8
  module EasyAppHelper
9
- EASY_APP_HELPER_VERSION = "1.0.4"
9
+ EASY_APP_HELPER_VERSION = "1.0.5"
10
10
  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 changes' do
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]} level is not specified."
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 ', '} levels are not specified."
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
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-07-07 00:00:00.000000000 Z
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