iron_core 0.2.0 → 0.3.0

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/iron_core/client.rb +58 -6
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -6,6 +6,7 @@ require_relative 'response_error'
6
6
  module IronCore
7
7
  class Client
8
8
  attr_accessor :content_type
9
+ attr_accessor :env
9
10
 
10
11
  def initialize(company, product, options = {}, default_options = {}, extra_options_list = [])
11
12
  @options_list = [:scheme, :host, :port, :user_agent, :http_gem] + extra_options_list
@@ -24,15 +25,38 @@ module IronCore
24
25
  end
25
26
  end
26
27
 
28
+ @env = options[:env] || options['env']
29
+ @env ||= ENV[company.upcase + '_' + product.upcase + '_ENV'] || ENV[product.upcase + '_ENV'] || ENV[company.upcase + '_ENV']
30
+
31
+ IronCore::Logger.info 'IronCore', "Setting env to '#{@env}'" unless @env.nil?
32
+
27
33
  load_from_hash('params', options)
34
+
28
35
  load_from_config(company, product, options[:config] || options['config'])
36
+
29
37
  load_from_config(company, product, ENV[company.upcase + '_' + product.upcase + '_CONFIG'])
38
+ load_from_config(company, product, ENV[product.upcase + '_CONFIG'])
30
39
  load_from_config(company, product, ENV[company.upcase + '_CONFIG'])
40
+
31
41
  load_from_env(company.upcase + '_' + product.upcase)
42
+ load_from_env(product.upcase)
32
43
  load_from_env(company.upcase)
33
- load_from_config(company, product, ".#{company}.json")
34
- load_from_config(company, product, "#{company}.json")
35
- load_from_config(company, product, "~/.#{company}.json")
44
+
45
+ suffixes = []
46
+ suffixes << "-#{env}" unless @env.nil?
47
+ suffixes << ''
48
+
49
+ suffixes.each do |suffix|
50
+ ['.json', ''].each do |ext|
51
+ ["#{company}-#{product}", product, company].each do |config_base|
52
+ load_from_config(company, product, "#{config_base}#{suffix}#{ext}")
53
+ load_from_config(company, product, ".#{config_base}#{suffix}#{ext}")
54
+ load_from_config(company, product, "~/#{config_base}#{suffix}#{ext}")
55
+ load_from_config(company, product, "~/.#{config_base}#{suffix}#{ext}")
56
+ end
57
+ end
58
+ end
59
+
36
60
  load_from_hash('defaults', default_options)
37
61
  load_from_hash('defaults', {:user_agent => 'iron_core_ruby-' + IronCore.version})
38
62
 
@@ -65,15 +89,43 @@ module IronCore
65
89
  end
66
90
  end
67
91
 
92
+ def get_sub_hash(hash, subs)
93
+ return nil if hash.nil?
94
+
95
+ subs.each do |sub|
96
+ return nil if hash[sub].nil?
97
+
98
+ hash = hash[sub]
99
+ end
100
+
101
+ hash
102
+ end
103
+
68
104
  def load_from_config(company, product, config_file)
69
105
  return if config_file.nil?
70
106
 
71
107
  if File.exists?(File.expand_path(config_file))
72
108
  config = JSON.load(File.read(File.expand_path(config_file)))
73
109
 
74
- load_from_hash(config_file, config["#{company}_#{product}"])
75
- load_from_hash(config_file, config[company])
76
- load_from_hash(config_file, config)
110
+ unless @env.nil?
111
+ load_from_hash(config_file, get_sub_hash(config, [@env, "#{company}_#{product}"]))
112
+ load_from_hash(config_file, get_sub_hash(config, [@env, company, product]))
113
+ load_from_hash(config_file, get_sub_hash(config, [@env, product]))
114
+ load_from_hash(config_file, get_sub_hash(config, [@env, company]))
115
+
116
+ load_from_hash(config_file, get_sub_hash(config, ["#{company}_#{product}", @env]))
117
+ load_from_hash(config_file, get_sub_hash(config, [company, product, @env]))
118
+ load_from_hash(config_file, get_sub_hash(config, [product, @env]))
119
+ load_from_hash(config_file, get_sub_hash(config, [company, @env]))
120
+
121
+ load_from_hash(config_file, get_sub_hash(config, [@env]))
122
+ end
123
+
124
+ load_from_hash(config_file, get_sub_hash(config, ["#{company}_#{product}"]))
125
+ load_from_hash(config_file, get_sub_hash(config, [company, product]))
126
+ load_from_hash(config_file, get_sub_hash(config, [product]))
127
+ load_from_hash(config_file, get_sub_hash(config, [company]))
128
+ load_from_hash(config_file, get_sub_hash(config, []))
77
129
  end
78
130
  end
79
131
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-10 00:00:00.000000000 Z
13
+ date: 2012-07-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: -839868627
92
+ hash: -448638065
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements: