thor-addons 0.1.2 → 0.1.3

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: 823a3001351110a2e13396c42de0450a29bb715e
4
- data.tar.gz: b2271ad7c3d0984426354c2668626fd15feab155
3
+ metadata.gz: fe504337d71eb421b7e686edcaaf999deafb7628
4
+ data.tar.gz: 6289a2a15f4d44a9e69680834f8fffc4b9a7c7c3
5
5
  SHA512:
6
- metadata.gz: a4550e2a28fa23e26f8adb39773a671ef9133765f214f61f01e0b4850f3a7d499cfd5e51e0ba590de1928c5129d6117d773d8380754458a2097c312a8a49e85a
7
- data.tar.gz: 07db6721c767a1078a86ff8c8905793058b4277f633dd87d1e81ad68f5c493360c48ce00cac2cf3cd3d23cbeb6805dc8d1b9ea0dfd516876b048f895190af829
6
+ metadata.gz: a7c1f13322c537f4302ece4d3b051ba4bd1e6d5edb1e1be3a7f4dd2c6f68a0c02db6073f39e44b519caad44560112ade00fdfdc902a5d60b92a6a8af6a0ef337
7
+ data.tar.gz: ba538f94df0b4df7ef4f781eccdb5c89f912a8fd2b4ba2679ee6ebb753e986f21e6b320e07a46c79b53165f68ce18fe0ee3d62f4aca20a047f5fa21d1dea8356
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.1.3 (08/08/2017)
2
+
3
+ BUG FIXES:
4
+
5
+ * Fix initialization bug #2 ([#4](https://github.com/eredi93/thor-addons/pull/4))
6
+
1
7
  0.1.2 (05/08/2017)
2
8
 
3
9
  BUG FIXES:
@@ -3,7 +3,7 @@ module ThorAddons
3
3
  attr_reader :current_command_name, :defaults, :invoked_via_subcommand, :invocations
4
4
 
5
5
  def initialize(args = [], local_options = {}, config = {})
6
- @current_command_name = config[:current_command].name
6
+ @current_command_name = config[:current_command] ? config[:current_command].name : nil
7
7
  @defaults = load_defaults(config.dup)
8
8
  @invoked_via_subcommand = config[:invoked_via_subcommand]
9
9
  @invocations = config[:invocations]
@@ -35,7 +35,7 @@ module ThorAddons
35
35
  merge(new_options, options_from_env)
36
36
  end
37
37
 
38
- ::Thor::CoreExt::HashWithIndifferentAccess.new(add_defaults(new_options))
38
+ hash_with_indifferent_access(add_defaults(new_options))
39
39
  end
40
40
 
41
41
  private
@@ -55,16 +55,17 @@ module ThorAddons
55
55
  end
56
56
 
57
57
  def options_from_env
58
+ opts = {}
58
59
  defaults.keys.inject({}) do |memo, option|
59
60
  env = option.to_s.upcase
60
- memo[option] = ENV[env] unless ENV[env].nil?
61
+ opts[option] = ENV[env] unless ENV[env].nil?
61
62
 
62
- if envs_aliases.keys.include?(env) && memo[option].nil?
63
- memo[option] = ENV[envs_aliases[env]] unless ENV[envs_aliases[env]].nil?
64
- end
63
+ next unless envs_aliases.keys.include?(env) && opts[option].nil? && ENV[envs_aliases[env]]
65
64
 
66
- memo
65
+ opts[option] = ENV[envs_aliases[env]]
67
66
  end
67
+
68
+ hash_with_indifferent_access(opts)
68
69
  end
69
70
 
70
71
  def options_from_config(config_file)
@@ -75,17 +76,21 @@ module ThorAddons
75
76
 
76
77
  data = YAML.load_file(config_file)
77
78
  command_options = {}
79
+ global = data["global"] || {}
80
+
81
+ return hash_with_indifferent_access(global) if current_command_name.nil?
82
+
78
83
  if invoked_via_subcommand
79
84
  invocations.map { |k,v| v }.flatten.each do |subcommand|
80
85
  next if data[subcommand].nil? || data[subcommand][current_command_name].nil?
81
86
 
82
87
  command_options.merge!(data[subcommand][current_command_name])
83
88
  end
89
+ else
90
+ command_options.merge!(data[current_command_name]) unless data[current_command_name].nil?
84
91
  end
85
92
 
86
- global = data["global"] || {}
87
-
88
- ::Thor::CoreExt::HashWithIndifferentAccess.new(global.merge(command_options))
93
+ hash_with_indifferent_access(global.merge(command_options))
89
94
  end
90
95
 
91
96
  def add_defaults(hash)
@@ -123,5 +128,9 @@ module ThorAddons
123
128
  memo
124
129
  end
125
130
  end
131
+
132
+ def hash_with_indifferent_access(hash)
133
+ ::Thor::CoreExt::HashWithIndifferentAccess.new(hash)
134
+ end
126
135
  end
127
136
  end
@@ -1,3 +1,3 @@
1
1
  module ThorAddons
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-addons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacopo Scrinzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-05 00:00:00.000000000 Z
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor