fwissr 1.0.1 → 1.0.2
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 +15 -7
- data/lib/fwissr.rb +53 -16
- data/lib/fwissr/registry.rb +6 -0
- data/lib/fwissr/source.rb +8 -1
- data/lib/fwissr/source/file.rb +7 -0
- data/lib/fwissr/source/mongodb.rb +21 -1
- data/lib/fwissr/version.rb +2 -1
- metadata +47 -40
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjAwYWY0ZDQ1ODQwZWM2ZGY5MDEwZDFlMmUwODM5OGYzYWU0ZWEzZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzNiZjU0MzQwOTRiZDkzYzIwNGNhMDMyODk3OGU5MjFmYzg0MjZkMw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODU1NmM4ZDFhZjU2NmMzMmQ3YTVmMzZjY2UyMjVlMTI4ODJlYzc4MmJjOTY4
|
10
|
+
NjVlMDFjY2VmMTBhZGUyZDcyZDE3ODBlMzhkZjNlZjU1YWU3OTJiYTAwYjAz
|
11
|
+
M2VjOGNjYjQxYzgzYjU2NTQ0MGE5NWJlNjQ3NjU0MGMzN2Y4ZGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDA0NmIzM2RlYzI1Mzg0NjE0NGY3M2ZlOTc2YTEyODUxODVjMWE3YzMwMjVm
|
14
|
+
MzgxODAwYzhjYzcyMzZjOGQ3MGE0MmNjMDJhNzViMWExZGE0MDRkMzc0OGMx
|
15
|
+
OTU4YWFmZjgwYTRiNjJkOTMwNTRiZWE5MzFhMTJkZGE0YzQyMzE=
|
data/lib/fwissr.rb
CHANGED
@@ -17,17 +17,14 @@ require 'fwissr/source'
|
|
17
17
|
require 'fwissr/registry'
|
18
18
|
|
19
19
|
#
|
20
|
-
#
|
21
|
-
# ===============
|
20
|
+
# Fwissr loads all conf files in directories: +/etc/fwissr/+ and +~/.fwissr/+
|
22
21
|
#
|
23
|
-
#
|
22
|
+
# Two conf files are handled differently: +/etc/fwissr/fwissr.json+ and +~/.fwissr/fwissr.json+
|
24
23
|
#
|
25
|
-
#
|
24
|
+
# These two main conf files are 'top_level' ones and so their settings are added to registry root. They can
|
25
|
+
# too contain a +fwissr_sources+ setting that is used to setup additional sources.
|
26
26
|
#
|
27
|
-
#
|
28
|
-
# too contain a +fwissr_sources+ setting that is then used to setup additional sources.
|
29
|
-
#
|
30
|
-
# Global registry is accessed with Fwissr#[] method
|
27
|
+
# Registry is accessed with Fwissr#[] method
|
31
28
|
#
|
32
29
|
# @example +/etc/fwissr/fwissr.json+ file:
|
33
30
|
#
|
@@ -38,7 +35,7 @@ require 'fwissr/registry'
|
|
38
35
|
# { 'mongodb': 'mongodb://db1.example.net/my_app', 'collection': 'config', 'refresh': true },
|
39
36
|
# ],
|
40
37
|
# 'fwissr_refresh_period': 30
|
41
|
-
#
|
38
|
+
# }
|
42
39
|
#
|
43
40
|
module Fwissr
|
44
41
|
|
@@ -55,13 +52,19 @@ module Fwissr
|
|
55
52
|
attr_writer :main_conf_path, :main_user_conf_path
|
56
53
|
|
57
54
|
# Main config files directory
|
55
|
+
#
|
58
56
|
# @api private
|
57
|
+
#
|
58
|
+
# @return [String] Directory path
|
59
59
|
def main_conf_path
|
60
60
|
@main_conf_path ||= DEFAULT_MAIN_CONF_PATH
|
61
61
|
end
|
62
62
|
|
63
63
|
# User's specific config files directory
|
64
|
+
#
|
64
65
|
# @api private
|
66
|
+
#
|
67
|
+
# @return [String] Directory path
|
65
68
|
def main_user_conf_path
|
66
69
|
@main_user_conf_path ||= File.join(Fwissr.find_home, DEFAULT_MAIN_USER_CONF_DIR)
|
67
70
|
end
|
@@ -70,6 +73,8 @@ module Fwissr
|
|
70
73
|
#
|
71
74
|
# @note Borrowed from rubygems
|
72
75
|
# @api private
|
76
|
+
#
|
77
|
+
# @return [String] Directory path
|
73
78
|
def find_home
|
74
79
|
['HOME', 'USERPROFILE'].each do |homekey|
|
75
80
|
return ENV[homekey] if ENV[homekey]
|
@@ -91,6 +96,7 @@ module Fwissr
|
|
91
96
|
end
|
92
97
|
|
93
98
|
# Parse command line arguments
|
99
|
+
#
|
94
100
|
# @api private
|
95
101
|
def parse_args!(argv)
|
96
102
|
args = {
|
@@ -149,8 +155,11 @@ module Fwissr
|
|
149
155
|
args
|
150
156
|
end
|
151
157
|
|
152
|
-
# Load
|
158
|
+
# Load registry
|
159
|
+
#
|
153
160
|
# @api private
|
161
|
+
#
|
162
|
+
# @return [Hash] Registry
|
154
163
|
def global_registry
|
155
164
|
@global_registry ||= begin
|
156
165
|
result = Fwissr::Registry.new('refresh_period' => self.main_conf['fwissr_refresh_period'])
|
@@ -179,7 +188,10 @@ module Fwissr
|
|
179
188
|
end
|
180
189
|
|
181
190
|
# Main config
|
191
|
+
#
|
182
192
|
# @api private
|
193
|
+
#
|
194
|
+
# @return [Hash] Configuration from main +fwissr.json+ files
|
183
195
|
def main_conf
|
184
196
|
@main_conf ||= begin
|
185
197
|
result = { }
|
@@ -197,34 +209,42 @@ module Fwissr
|
|
197
209
|
end
|
198
210
|
|
199
211
|
# Main config file
|
212
|
+
#
|
200
213
|
# @api private
|
214
|
+
#
|
215
|
+
# @return [String] File path
|
201
216
|
def main_conf_file
|
202
217
|
@main_conf_file ||= File.join(self.main_conf_path, MAIN_CONF_FILE)
|
203
218
|
end
|
204
219
|
|
205
220
|
# Main user's config file
|
221
|
+
#
|
206
222
|
# @api private
|
223
|
+
#
|
224
|
+
# @return [String] File path
|
207
225
|
def main_user_conf_file
|
208
226
|
@main_user_conf_file ||= File.join(self.main_user_conf_path, MAIN_CONF_FILE)
|
209
227
|
end
|
210
228
|
|
211
|
-
#
|
229
|
+
# Registry accessor
|
212
230
|
#
|
213
|
-
# @param key [String]
|
214
|
-
# @return [Object]
|
231
|
+
# @param key [String] Setting key
|
232
|
+
# @return [Object] Setting value
|
215
233
|
def [](key)
|
216
234
|
self.global_registry[key]
|
217
235
|
end
|
218
236
|
|
219
237
|
alias :get :[]
|
220
238
|
|
221
|
-
# Dumps
|
239
|
+
# Dumps registry keys
|
222
240
|
#
|
223
241
|
# @return [Array] Keys list
|
224
242
|
def keys
|
225
243
|
self.global_registry.keys
|
226
244
|
end
|
227
245
|
|
246
|
+
# Dumps registry
|
247
|
+
#
|
228
248
|
# @return [Hash] The entire registry
|
229
249
|
def dump
|
230
250
|
self.global_registry.dump
|
@@ -237,9 +257,10 @@ module Fwissr
|
|
237
257
|
|
238
258
|
# Parse a configuration file
|
239
259
|
#
|
240
|
-
# @param conf_file_path [String] Configuration file path
|
241
|
-
# @return [Hash] Parse configuration
|
242
260
|
# @api private
|
261
|
+
#
|
262
|
+
# @param conf_file_path [String] Configuration file path
|
263
|
+
# @return [Hash] Parsed configuration
|
243
264
|
def parse_conf_file(conf_file_path)
|
244
265
|
conf_file_ext = File.extname(conf_file_path)
|
245
266
|
|
@@ -259,14 +280,26 @@ module Fwissr
|
|
259
280
|
end
|
260
281
|
end
|
261
282
|
|
283
|
+
# Merge two conf files
|
284
|
+
#
|
262
285
|
# @note Borrowed from rails
|
263
286
|
# @api private
|
287
|
+
#
|
288
|
+
# @param to_hash [Hash] Merge to this conf
|
289
|
+
# @param other_hash [Hash] Merge this conf
|
290
|
+
# @return [Hash] Merged configuration
|
264
291
|
def merge_conf(to_hash, other_hash)
|
265
292
|
self.merge_conf!(to_hash.dup, other_hash)
|
266
293
|
end
|
267
294
|
|
295
|
+
# Merge two conf files (in place)
|
296
|
+
#
|
268
297
|
# @note Borrowed from rails
|
269
298
|
# @api private
|
299
|
+
#
|
300
|
+
# @param to_hash [Hash] Merge to this conf
|
301
|
+
# @param other_hash [Hash] Merge this conf
|
302
|
+
# @return [Hash] Merged configuration
|
270
303
|
def merge_conf!(to_hash, other_hash)
|
271
304
|
other_hash.each_pair do |k,v|
|
272
305
|
tv = to_hash[k]
|
@@ -276,7 +309,11 @@ module Fwissr
|
|
276
309
|
end
|
277
310
|
|
278
311
|
# Simple deep freezer
|
312
|
+
#
|
279
313
|
# @api private
|
314
|
+
#
|
315
|
+
# @param obj [Object] Object to freeze
|
316
|
+
# @return [Object] Deep frozen object
|
280
317
|
def deep_freeze(obj)
|
281
318
|
if obj.is_a?(Hash)
|
282
319
|
obj.each do |k, v|
|
data/lib/fwissr/registry.rb
CHANGED
@@ -11,8 +11,10 @@ module Fwissr
|
|
11
11
|
# API
|
12
12
|
#
|
13
13
|
|
14
|
+
# [Integer] Refresh period
|
14
15
|
attr_reader :refresh_period
|
15
16
|
|
17
|
+
# Init
|
16
18
|
def initialize(options = { })
|
17
19
|
@refresh_period = options['refresh_period'] || DEFAULT_REFRESH_PERIOD
|
18
20
|
|
@@ -54,6 +56,7 @@ module Fwissr
|
|
54
56
|
# Get a registry key value
|
55
57
|
#
|
56
58
|
# @param key [String] Key
|
59
|
+
# @return [Object] Value
|
57
60
|
def get(key)
|
58
61
|
# split key
|
59
62
|
key_ary = key.split('/')
|
@@ -99,6 +102,8 @@ module Fwissr
|
|
99
102
|
end
|
100
103
|
|
101
104
|
# @api private
|
105
|
+
#
|
106
|
+
# @return [true,false] Is there at least one refreshable source ?
|
102
107
|
def have_refreshable_source?
|
103
108
|
@semaphore.synchronize do
|
104
109
|
!@sources.find { |source| source.can_refresh? }.nil?
|
@@ -160,6 +165,7 @@ module Fwissr
|
|
160
165
|
end
|
161
166
|
|
162
167
|
# Helper for #keys
|
168
|
+
#
|
163
169
|
# @api private
|
164
170
|
def _keys(result, key_ary, hash)
|
165
171
|
hash.each do |key, value|
|
data/lib/fwissr/source.rb
CHANGED
@@ -5,6 +5,10 @@ class Fwissr::Source
|
|
5
5
|
autoload :Mongodb, 'fwissr/source/mongodb'
|
6
6
|
|
7
7
|
class << self
|
8
|
+
# Instanciate source from settings
|
9
|
+
#
|
10
|
+
# @param settings [Hash] Source settings
|
11
|
+
# @return [Fwissr::Source::File, Fwissr::Source::Mongodb] Source instance
|
8
12
|
def from_settings(settings)
|
9
13
|
raise "Unexpected source settings class: #{settings.inspect}" unless settings.is_a?(Hash)
|
10
14
|
|
@@ -23,8 +27,10 @@ class Fwissr::Source
|
|
23
27
|
# API
|
24
28
|
#
|
25
29
|
|
30
|
+
# [Hash] Source options
|
26
31
|
attr_reader :options
|
27
32
|
|
33
|
+
# Init
|
28
34
|
def initialize(options = { })
|
29
35
|
@options = options
|
30
36
|
|
@@ -38,7 +44,7 @@ class Fwissr::Source
|
|
38
44
|
|
39
45
|
# Source can be refreshed ?
|
40
46
|
#
|
41
|
-
# @return [
|
47
|
+
# @return [true,false] Is it a refreshable source ?
|
42
48
|
def can_refresh?
|
43
49
|
@options && (@options['refresh'] == true)
|
44
50
|
end
|
@@ -59,6 +65,7 @@ class Fwissr::Source
|
|
59
65
|
# Fetch conf from source
|
60
66
|
#
|
61
67
|
# @abstract MUST be implemented by child class
|
68
|
+
#
|
62
69
|
# @return [Hash] The source's configuration
|
63
70
|
def fetch_conf
|
64
71
|
raise "not implemented"
|
data/lib/fwissr/source/file.rb
CHANGED
@@ -30,8 +30,10 @@ class Fwissr::Source::File < Fwissr::Source
|
|
30
30
|
end # class << self
|
31
31
|
|
32
32
|
|
33
|
+
# [Array] Files names corresponding to 'top level' configurations
|
33
34
|
TOP_LEVEL_CONF_FILES = [ 'fwissr' ].freeze
|
34
35
|
|
36
|
+
# [String] File path
|
35
37
|
attr_reader :path
|
36
38
|
|
37
39
|
#
|
@@ -71,7 +73,12 @@ class Fwissr::Source::File < Fwissr::Source
|
|
71
73
|
# PRIVATE
|
72
74
|
#
|
73
75
|
|
76
|
+
# Merge two conf files
|
77
|
+
#
|
74
78
|
# @api private
|
79
|
+
#
|
80
|
+
# @param result [Hash] Merge to that existing conf
|
81
|
+
# @param conf_file_path [String] File path
|
75
82
|
def merge_conf_file!(result, conf_file_path)
|
76
83
|
# parse conf file
|
77
84
|
conf = Fwissr.parse_conf_file(conf_file_path)
|
@@ -17,8 +17,10 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
17
17
|
# @api private
|
18
18
|
class Connection
|
19
19
|
|
20
|
+
# [String] Database name
|
20
21
|
attr_reader :db_name
|
21
22
|
|
23
|
+
# Init
|
22
24
|
def initialize(uri)
|
23
25
|
raise "URI is missing: #{uri}" if (uri.nil? || uri == '')
|
24
26
|
|
@@ -59,6 +61,9 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
59
61
|
end
|
60
62
|
|
61
63
|
# Database collection
|
64
|
+
#
|
65
|
+
# @param col_name [String] Collection name
|
66
|
+
# @return [Object] Collection handler
|
62
67
|
def collection(col_name)
|
63
68
|
@collections[col_name] ||= begin
|
64
69
|
case @kind
|
@@ -71,6 +76,9 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
71
76
|
end
|
72
77
|
|
73
78
|
# Returns an Enumerator for all documents from given collection
|
79
|
+
#
|
80
|
+
# @param col_name [String] Collection name
|
81
|
+
# @return [Enumerator] Collection enumerator
|
74
82
|
def fetch(col_name)
|
75
83
|
case @kind
|
76
84
|
when :moped, :mongo
|
@@ -79,6 +87,9 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
79
87
|
end
|
80
88
|
|
81
89
|
# Insert document in collection
|
90
|
+
#
|
91
|
+
# @param col_name [String] Collection name
|
92
|
+
# @param doc [Hash] Document to insert
|
82
93
|
def insert(col_name, doc)
|
83
94
|
case @kind
|
84
95
|
when :moped, :mongo
|
@@ -87,6 +98,8 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
87
98
|
end
|
88
99
|
|
89
100
|
# Create a collection
|
101
|
+
#
|
102
|
+
# @param col_name [String] Collection name
|
90
103
|
def create_collection(col_name)
|
91
104
|
case @kind
|
92
105
|
when :moped
|
@@ -97,6 +110,8 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
97
110
|
end
|
98
111
|
|
99
112
|
# Drop database
|
113
|
+
#
|
114
|
+
# @param db_name [String] Database name
|
100
115
|
def drop_database(db_name)
|
101
116
|
case @kind
|
102
117
|
when :moped
|
@@ -127,7 +142,12 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
127
142
|
self.new(conn, settings['collection'], options)
|
128
143
|
end
|
129
144
|
|
145
|
+
# Get a memoized connection
|
146
|
+
#
|
130
147
|
# @api private
|
148
|
+
#
|
149
|
+
# @param uri [String] Connection URI
|
150
|
+
# @return [Fwissr::Source::Mongodb::Connection] Connection handler
|
131
151
|
def connection_for_uri(uri)
|
132
152
|
@connections ||= { }
|
133
153
|
@connections[uri] ||= Fwissr::Source::Mongodb::Connection.new(uri)
|
@@ -135,7 +155,7 @@ class Fwissr::Source::Mongodb < Fwissr::Source
|
|
135
155
|
|
136
156
|
end # class << self
|
137
157
|
|
138
|
-
|
158
|
+
# [Array] Collection names corresponding to 'top level' configurations
|
139
159
|
TOP_LEVEL_COLLECTIONS = [ 'fwissr' ].freeze
|
140
160
|
|
141
161
|
attr_reader :conn, :collection_name
|
data/lib/fwissr/version.rb
CHANGED
metadata
CHANGED
@@ -1,46 +1,54 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fwissr
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Fotonauts Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
15
14
|
name: yajl-ruby
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
23
20
|
type: :runtime
|
24
|
-
version_requirements: *id001
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: rspec
|
27
21
|
prerelease: false
|
28
|
-
|
29
|
-
requirements:
|
30
|
-
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
31
34
|
type: :development
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ! ' A simple configuration registry tool by Fotonauts.
|
42
|
+
|
43
|
+
'
|
44
|
+
email:
|
35
45
|
- aymerick@fotonauts.com
|
36
46
|
- oct@fotonauts.com
|
37
|
-
executables:
|
47
|
+
executables:
|
38
48
|
- fwissr
|
39
49
|
extensions: []
|
40
|
-
|
41
50
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
51
|
+
files:
|
44
52
|
- LICENSE
|
45
53
|
- Rakefile
|
46
54
|
- README.md
|
@@ -53,26 +61,25 @@ files:
|
|
53
61
|
- lib/fwissr.rb
|
54
62
|
homepage: https://github.com/fotonauts/fwissr
|
55
63
|
licenses: []
|
56
|
-
|
57
64
|
metadata: {}
|
58
|
-
|
59
65
|
post_install_message:
|
60
66
|
rdoc_options: []
|
61
|
-
|
62
|
-
require_paths:
|
67
|
+
require_paths:
|
63
68
|
- lib
|
64
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
70
79
|
requirements: []
|
71
|
-
|
72
80
|
rubyforge_project:
|
73
81
|
rubygems_version: 2.1.11
|
74
82
|
signing_key:
|
75
83
|
specification_version: 4
|
76
84
|
summary: Fwissr
|
77
85
|
test_files: []
|
78
|
-
|