merlin 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/merlin/configuration.rb +34 -2
- data/lib/merlin/version.rb +1 -1
- metadata +2 -2
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Merlin
|
2
4
|
class Configuration
|
3
5
|
attr_reader :raw
|
@@ -28,13 +30,43 @@ module Merlin
|
|
28
30
|
|
29
31
|
response = connection.get "/config/#{@environment}.json"
|
30
32
|
if response.status == 200
|
31
|
-
response.body
|
33
|
+
result = response.body
|
34
|
+
dump_config(result) unless production_or_staging
|
35
|
+
result
|
32
36
|
else
|
33
37
|
{}
|
34
38
|
end
|
39
|
+
rescue Faraday::Error::ConnectionFailed => e
|
40
|
+
if production_or_staging
|
41
|
+
raise e
|
42
|
+
else
|
43
|
+
restore_config
|
44
|
+
end
|
35
45
|
end
|
36
46
|
|
37
|
-
|
47
|
+
def production_or_staging
|
48
|
+
["production", "staging"].include?(::Rails.env)
|
49
|
+
end
|
50
|
+
|
51
|
+
def dump_config(config)
|
52
|
+
print_message "ONLINE - dump config in '#{dump_filepath}'."
|
53
|
+
File.open(dump_filepath, "w") { |file| file.puts(YAML.dump(config)) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def restore_config
|
57
|
+
print_message "OFFLINE - restore config from '#{dump_filepath}'."
|
58
|
+
File.open(dump_filepath, "r") { |file| YAML.load(file) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def print_message(message)
|
62
|
+
merlin_message = "MERLIN: #{message}"
|
63
|
+
Rails.logger.warn(merlin_message)
|
64
|
+
puts merlin_message
|
65
|
+
end
|
66
|
+
|
67
|
+
def dump_filepath
|
68
|
+
File.join(::Rails.root, "tmp", "merlin_offline_dump.yml")
|
69
|
+
end
|
38
70
|
|
39
71
|
def merlin_server
|
40
72
|
@local_raw['merlin']
|
data/lib/merlin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merlin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09
|
12
|
+
date: 2012-11-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|