cncflora_commons 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/cncflora_commons.rb +2 -110
  2. metadata +1 -1
@@ -73,128 +73,20 @@ def search(db,index,query)
73
73
  result
74
74
  end
75
75
 
76
- def flatten(obj)
77
- flat = {}
78
- if obj["dir"] && obj["nodes"] then
79
- obj["nodes"].each { |n|
80
- flat = flat.merge(flatten(n))
81
- }
82
- else
83
- key = obj["key"].gsub("/","_").gsub("-","_")
84
- flat[key[1..key.length].to_sym]=obj["value"]
85
- end
86
- flat
87
- end
88
-
89
- def etcd2config(server,prefix="")
90
- config = flatten( http_get("#{server}/v2/keys/?recursive=true")["node"] )
91
- config.keys.each {|k|
92
- if k.to_s.end_with?("_url") then
93
- config[k.to_s.gsub(prefix,"").gsub("_url","").to_sym] = config[k]
94
- end
95
- }
96
- config
97
- end
98
-
99
76
  def setup(file)
100
77
  config_file file
101
78
 
102
- if ENV["DB"] then
103
- set :db, ENV["DB"]
104
- end
105
-
106
- if ENV["CONTEXT"] then
107
- set :context, ENV["CONTEXT"]
108
- else
109
- set :context, "connect"
110
- end
111
-
112
- if ENV["PREFIX"] then
113
- set :prefix, ENV["PREFIX"]
114
- else
115
- set :prefix, ""
116
- end
117
-
118
- if ENV["BASE"] then
119
- set :base, ENV["BASE"]
120
- else
121
- set :base, ""
122
- end
123
-
124
- if settings.prefix.length >= 1 then
125
- set :prefix, "#{settings.prefix}_"
126
- end
127
-
128
- if ENV["ETCD_PORT_4001_TCP_ADDR"] then
129
- set :etcd, "http://#{ENV["ETCD_PORT_4001_TCP_ADDR"]}:#{ENV["ETCD_PORT_4001_TCP_PORT"]}"
130
- elsif ENV["ETCD"] then
131
- set :etcd, ENV["ETCD"]
132
- elsif settings.etcd then
133
- else
134
- set :etcd, "http://localhost:4001"
135
- end
136
-
137
- @config = etcd2config(settings.etcd,settings.prefix)
138
-
139
- onchange(settings.etcd,settings.prefix) do |newconfig|
140
- @config = newconfig
141
- setup! newconfig
142
- end
79
+ ENV.each {|k,v| set k.to_sym, v}
143
80
 
144
81
  use Rack::Session::Pool
145
82
 
146
83
  set :session_secret, '1flora2'
147
84
  set :views, 'src/views'
148
85
 
149
- setup! @config
150
- end
151
-
152
- def setup!(config)
153
-
154
86
  if settings.lang then
155
- config[:strings] = JSON.parse(File.read("src/locales/#{settings.lang}.json", :encoding => "BINARY"))
156
- end
157
-
158
- if ENV["DATAHUB_PORT_8080_TCP_ADDR"] then
159
- config[:datahub] = "http://#{ENV["DATAHUB_PORT_8080_TCP_ADDR"]}:#{ENV["DATAHUB_PORT_8080_TCP_PORT"]}"
160
- end
161
-
162
- if config.has_key? :elasticsearch then
163
- config[:elasticsearch] = "#{config[:elasticsearch]}"
164
- else
165
- config[:elasticsearch] = "#{config[:datahub]}"
87
+ settings.strings = JSON.parse(File.read("src/locales/#{settings.lang}.json", :encoding => "BINARY"))
166
88
  end
167
89
 
168
- if config.has_key? :couchdb then
169
- config[:couchdb] = "#{config[:couchdb]}"
170
- else
171
- config[:couchdb] = "#{config[:datahub]}"
172
- end
173
-
174
- if settings.context then
175
- config[:context] = settings.context
176
- end
177
-
178
- if settings.base then
179
- config[:base] = settings.base
180
- end
181
-
182
- config.keys.each { |key| set key, config[key] }
183
-
184
- set :config, config
185
-
186
90
  puts "Config loaded"
187
- puts config
188
-
189
- config
190
- end
191
-
192
- def onchange(etcd,prefix="")
193
- Thread.new do
194
- while true do
195
- http_get("#{ etcd }/v2/keys/?recursive=true&wait=true")
196
- yield etcd2config(etcd,prefix)
197
- end
198
- end
199
91
  end
200
92
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cncflora_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.28
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: