easy_app_helper 1.0.11 → 1.0.12

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: 39557d4f84525b6de38404fecf05ce2eae6f7144
4
- data.tar.gz: 454cec936616e65211a9753ca09a39b0f3923dda
3
+ metadata.gz: 3cff55825961e2cb5ae6ade6a3cd3c6f850e73e7
4
+ data.tar.gz: f371a891e6874165e647a065333fbe506dcc4bdc
5
5
  SHA512:
6
- metadata.gz: 8b2bbf54f247a69dce1595dbd03006922b5c252e92818bdf04266c2cac82b0738bff5f9d15d8e1bb5ddfca4c2a81d30495b505fb9c447d55cab22ef51cc031ff
7
- data.tar.gz: 6c8b3dfbfbda115b2dfa154247dedf677bcebd2b08ffe67e7a276dd5a7b7ffbb306cf7c5613f63e5aab764edde43c2110e3fd564d4e849f3fb4a6cdc2fc53e53
6
+ metadata.gz: 0b024e94fddf2b435053766509a8c2157eb26498fea8b2719e1663e8aec745e6908059ba007cd2a450a0254ef5080f98683f03687645ebd6e76a33288d99b3d4
7
+ data.tar.gz: ffc0ebaa8de0b04b7327d30616ec13e3f4203a70f1adbfd7b5e8d4d1625225485e9de03cac2403ef6b00bc88961dee238ba3dd481968e36380b61232329438b7
@@ -42,7 +42,6 @@ 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
46
45
 
47
46
  ADMIN_CONFIG_FILENAME = EasyAppHelper.name
48
47
  INTRODUCED_SORTED_LAYERS = [:specific_file, :user, :global, :internal, :system]
@@ -170,9 +169,10 @@ class EasyAppHelper::Core::Config
170
169
  if File.exists? filename_or_pattern and !File.directory? filename_or_pattern
171
170
  filename = filename_or_pattern
172
171
  else
173
- filename = find_file POSSIBLE_PLACES[layer], filename_or_pattern
172
+ places = Places.possible_config_places[layer]
173
+ filename = find_file places, filename_or_pattern
174
174
  end
175
- internal_configs[layer] = {content: load_config_file(filename), source: filename, origin: filename_or_pattern}
175
+ internal_configs[layer] = {content: load_config_file(filename, layer), source: filename, origin: filename_or_pattern}
176
176
  end
177
177
  ensure
178
178
  logger.info "No config file found for layer #{layer}." if filename.nil?
@@ -204,15 +204,15 @@ class EasyAppHelper::Core::Config
204
204
  nil
205
205
  end
206
206
 
207
- def load_config_file(conf_filename)
207
+ def load_config_file(conf_filename, layer=nil)
208
208
  conf = {}
209
209
  return conf if conf_filename.nil?
210
-
210
+ ext = layer.nil? ? '' : " as layer #{layer}"
211
211
  begin
212
- logger.debug "Loading config file \"#{conf_filename}\""
212
+ logger.debug "Loading config file \"#{conf_filename}\"#{ext}"
213
213
  conf = Hash[YAML::load(open(conf_filename)).map { |k, v| [k.to_sym, v] }]
214
214
  rescue => e
215
- logger.error "Invalid config file \"#{conf_filename}\". Skipped as not respecting YAML syntax!\n#{e.message}"
215
+ logger.error "Invalid config file \"#{conf_filename}\"#{ext}. Skipped as not respecting YAML syntax!\n#{e.message}"
216
216
  end
217
217
  conf
218
218
  end
@@ -11,6 +11,9 @@ module EasyAppHelper::Core::HashesMergePolicies
11
11
  # Performs a merge at the second level of hashes.
12
12
  # simple entries and arrays are overridden.
13
13
  def hashes_second_level_merge(h1, h2)
14
+ return [] if h1.nil? && h2.nil?
15
+ return h1 if h2.nil?
16
+ return h2 if h1.nil?
14
17
  h2.each do |key, v|
15
18
  if h1[key] and h1[key].is_a?(Hash)
16
19
  # Merges hashes
@@ -9,76 +9,79 @@
9
9
  # that provides a list of OS dependant paths.
10
10
  # The only method that should be used is the #get_os_module method that returns this module.
11
11
  # TODO: Add equivalent for Mac
12
- class EasyAppHelper::Core::Config::Places
13
12
 
14
- module Helper
15
-
16
- def gem_root_path
17
- spec = Gem::Specification.find_by_name("your_gem_name")
18
- gem_root = spec.gem_dir
19
- end
20
-
21
- def get_internal_config_place
22
- [File.expand_path('../../etc', $PROGRAM_NAME), File.expand_path('../../config', $PROGRAM_NAME)]
13
+ module EasyAppHelper
14
+ module Core
15
+ class Config
16
+ module Places
17
+
18
+ OS_FLAVOURS = {
19
+ mingw32: :windows,
20
+ linux: :unix
21
+ }
22
+ DEFAULT_OS_FLAVOUR = :unix
23
+
24
+ FLAVOUR_PLACES = {
25
+ unix: {
26
+ internal: [],
27
+
28
+ system: ['/etc'],
29
+
30
+ # Where could be stored global wide configuration
31
+ global: %w(/etc /usr/local/etc),
32
+
33
+ # Where could be stored user configuration
34
+ user: ["#{ENV['HOME']}/.config"]
35
+ },
36
+ windows: {
37
+ internal: [],
38
+
39
+ system: ["#{ENV['systemRoot']}/Config"],
40
+
41
+ # Where could be stored global configuration
42
+ global: ["#{ENV['systemRoot']}/Config",
43
+ "#{ENV['ALLUSERSPROFILE']}/Application Data"],
44
+
45
+ # Where could be stored user configuration
46
+ user: [ENV['APPDATA']]
47
+ }
48
+ }
49
+
50
+
51
+ def self.os_flavour
52
+ flavour = OS_FLAVOURS[RbConfig::CONFIG['target_os'].to_sym]
53
+ flavour.nil? ? DEFAULT_OS_FLAVOUR : flavour
54
+ end
55
+
56
+ def self.gem_root_path(file=__FILE__)
57
+ file=__FILE__ if file.nil?
58
+ searcher = if Gem::Specification.respond_to? :find
59
+ # ruby 2.0
60
+ Gem::Specification
61
+ elsif Gem.respond_to? :searcher
62
+ # ruby 1.8/1.9
63
+ Gem.searcher.init_gemspecs
64
+ end
65
+ spec = unless searcher.nil?
66
+ searcher.find do |spec|
67
+ File.fnmatch(File.join(spec.full_gem_path,'*'), file)
68
+ end
69
+ end
70
+
71
+ spec.gem_dir
72
+ end
73
+
74
+
75
+ def self.possible_config_places(file_of_gem=nil)
76
+ root = gem_root_path file_of_gem
77
+ places = FLAVOUR_PLACES[os_flavour].dup
78
+ places[:internal] = %w(etc config).map do |place|
79
+ File.join root, place
80
+ end
81
+ places
82
+ end
83
+
84
+ end
23
85
  end
24
-
25
- def possible_config_places key
26
- POSSIBLE_PLACES[key]
27
- end
28
-
29
- end
30
-
31
-
32
- # Defines some places for Unix machines
33
- module Unix
34
-
35
- extend Helper
36
-
37
- POSSIBLE_PLACES = {
38
-
39
- internal: self.get_internal_config_place,
40
-
41
- system: ['/etc'],
42
-
43
- # Where could be stored global wide configuration
44
- global: ['/etc',
45
- '/usr/local/etc'],
46
-
47
- # Where could be stored user configuration
48
- user: ["#{ENV['HOME']}/.config"]
49
- }
50
- end
51
-
52
- # Defines some places for Windows machines
53
- module Windows
54
- extend Helper
55
-
56
- POSSIBLE_PLACES = {
57
-
58
- internal: self.get_internal_config_place,
59
-
60
- system: ["#{ENV['systemRoot']}/Config"],
61
-
62
- # Where could be stored global configuration
63
- global: ["#{ENV['systemRoot']}/Config",
64
- "#{ENV['ALLUSERSPROFILE']}/Application Data"],
65
-
66
- # Where could be stored user configuration
67
- user: [ENV['APPDATA']]
68
- }
69
86
  end
70
-
71
- CONF = {
72
- mingw32: Windows,
73
- linux: Unix
74
- }
75
- DEFAULT = Unix
76
-
77
-
78
- def self.get_os_module
79
- conf = CONF[RbConfig::CONFIG['target_os'].to_sym]
80
- conf.nil? ? DEFAULT : conf
81
- end
82
-
83
-
84
- end
87
+ end
@@ -6,5 +6,5 @@
6
6
  ################################################################################
7
7
 
8
8
  module EasyAppHelper
9
- EASY_APP_HELPER_VERSION = "1.0.11"
9
+ EASY_APP_HELPER_VERSION = "1.0.12"
10
10
  end
data/spec/config_spec.rb CHANGED
@@ -189,9 +189,6 @@ describe "The EasyAppHelper config object" do
189
189
 
190
190
  context "When a gem has its own :internal config file" do
191
191
  before(:all) do
192
- pp = EasyAppHelper.config.class.const_get :POSSIBLE_PLACES
193
- pp[:internal] = [File.expand_path('../../etc', __FILE__)]
194
- EasyAppHelper.config.class.const_set :POSSIBLE_PLACES, pp
195
192
  EasyAppHelper.config.script_filename = 'test_internal'
196
193
  end
197
194
 
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.11
4
+ version: 1.0.12
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-11-09 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler