coral_core 0.2.18 → 0.2.19
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.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/coral_core.gemspec +2 -2
- data/lib/coral_core/config.rb +73 -3
- data/lib/coral_core/util/data.rb +29 -0
- data/lib/coral_core/util/disk.rb +8 -3
- data/lib/coral_core.rb +4 -2
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.19
|
data/coral_core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "coral_core"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.19"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adrian Webb"]
|
12
|
-
s.date = "2013-05-
|
12
|
+
s.date = "2013-05-14"
|
13
13
|
s.description = "= coral_core\n\nThis library provides core data elements and utilities used in other Coral gems.\n\nThe Coral core library contains functionality that is utilized by other\nCoral gems by providing basic utilities like Git, Shell, Disk, and Data\nmanipulation libraries, a UI system, and a core data model that supports\nEvents, Commands, Repositories, and Memory (version controlled JSON \nobjects). This library is only used as a starting point for other systems.\n\nNote: This library is still very early in development!\n\n== Contributing to coral_core\n \n* Check out the latest {major}.{minor} branch to make sure the feature hasn't \n been implemented or the bug hasn't been fixed yet.\n* Check out the issue tracker to make sure someone already hasn't requested \n it and/or contributed it.\n* Fork the project.\n* Start a feature/bugfix branch.\n* Commit and push until you are happy with your contribution.\n* Make sure to add tests for it. This is important so I don't break it in a \n future version unintentionally.\n* Please try not to mess with the Rakefile, version, or history. If you want \n to have your own version, or is otherwise necessary, that is fine, but \n please isolate to its own commit so I can cherry-pick around it.\n\n== Copyright\n\nLicensed under GPLv3. See LICENSE.txt for further details.\n\nCopyright (c) 2013 Adrian Webb <adrian.webb@coraltech.net>\nCoral Technology Group LLC"
|
14
14
|
s.email = "adrian.webb@coraltech.net"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/coral_core/config.rb
CHANGED
@@ -4,8 +4,47 @@ class Config
|
|
4
4
|
|
5
5
|
#-----------------------------------------------------------------------------
|
6
6
|
# Global configuration
|
7
|
+
|
8
|
+
@@options = {}
|
9
|
+
|
10
|
+
#---
|
11
|
+
|
12
|
+
def self.options(contexts, force = true)
|
13
|
+
options = {}
|
14
|
+
|
15
|
+
unless contexts.is_a?(Array)
|
16
|
+
contexts = [ contexts ]
|
17
|
+
end
|
18
|
+
contexts.each do |name|
|
19
|
+
if @@options.has_key?(name)
|
20
|
+
options = Util::Data.merge([ options, @@options[name] ], force)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return options
|
24
|
+
end
|
25
|
+
|
26
|
+
#---
|
27
|
+
|
28
|
+
def self.set_options(context, options, force = true)
|
29
|
+
current_options = ( @@options.has_key?(context) ? @@options[context] : {} )
|
30
|
+
@@options[context] = Util::Data.merge([ current_options, options ], force)
|
31
|
+
end
|
32
|
+
|
33
|
+
#---
|
34
|
+
|
35
|
+
def self.clear_options(contexts)
|
36
|
+
unless contexts.is_a?(Array)
|
37
|
+
contexts = [ contexts ]
|
38
|
+
end
|
39
|
+
contexts.each do |name|
|
40
|
+
@@options.delete(name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
#-----------------------------------------------------------------------------
|
7
45
|
|
8
46
|
@@properties = {}
|
47
|
+
@@mutex = false
|
9
48
|
|
10
49
|
#---
|
11
50
|
|
@@ -16,7 +55,29 @@ class Config
|
|
16
55
|
#---
|
17
56
|
|
18
57
|
def self.set_property(name, value)
|
19
|
-
|
58
|
+
#dbg(value, "result -> #{name}")
|
59
|
+
@@properties[name] = value
|
60
|
+
save_properties
|
61
|
+
end
|
62
|
+
|
63
|
+
#---
|
64
|
+
|
65
|
+
def self.clear_property(name)
|
66
|
+
@@properties.delete(name)
|
67
|
+
save_properties
|
68
|
+
end
|
69
|
+
|
70
|
+
#---
|
71
|
+
|
72
|
+
def self.save_properties
|
73
|
+
log_options = options('coral_log')
|
74
|
+
|
75
|
+
unless Util::Data.empty?(log_options['config_log'])
|
76
|
+
config_log = log_options['config_log']
|
77
|
+
|
78
|
+
Util::Disk.write(config_log, JSON.generate(@@properties))
|
79
|
+
Util::Disk.close(config_log)
|
80
|
+
end
|
20
81
|
end
|
21
82
|
|
22
83
|
#-----------------------------------------------------------------------------
|
@@ -178,7 +239,7 @@ class Config
|
|
178
239
|
end
|
179
240
|
|
180
241
|
#-----------------------------------------------------------------------------
|
181
|
-
# Instance
|
242
|
+
# Instance generators
|
182
243
|
|
183
244
|
def self.ensure(config)
|
184
245
|
case config
|
@@ -190,11 +251,20 @@ class Config
|
|
190
251
|
return Config.new
|
191
252
|
end
|
192
253
|
|
254
|
+
#---
|
255
|
+
|
256
|
+
def self.init(options, contexts = [], defaults = {})
|
257
|
+
config = Coral::Config.new(Coral::Config.options(contexts), defaults)
|
258
|
+
config.import(options) unless Coral::Util::Data.empty?(options)
|
259
|
+
return config
|
260
|
+
end
|
261
|
+
|
193
262
|
#-----------------------------------------------------------------------------
|
194
263
|
# Configuration instance
|
195
264
|
|
196
265
|
def initialize(data = {}, defaults = {}, force = true)
|
197
|
-
@force
|
266
|
+
@force = force
|
267
|
+
@options = {}
|
198
268
|
|
199
269
|
if defaults.is_a?(Hash) && ! defaults.empty?
|
200
270
|
symbolized = {}
|
data/lib/coral_core/util/data.rb
CHANGED
@@ -185,6 +185,35 @@ class Data
|
|
185
185
|
#dbg(value, 'interpolate -> result')
|
186
186
|
return value
|
187
187
|
end
|
188
|
+
|
189
|
+
#-----------------------------------------------------------------------------
|
190
|
+
# Utilities
|
191
|
+
|
192
|
+
def self.prefix(prefix, data)
|
193
|
+
result = nil
|
194
|
+
|
195
|
+
unless prefix.is_a?(String) && ! empty?(prefix)
|
196
|
+
prefix = ''
|
197
|
+
end
|
198
|
+
|
199
|
+
case data
|
200
|
+
when String, Symbol
|
201
|
+
result = ( prefix.empty? ? data.to_s : prefix + '_' + data.to_s )
|
202
|
+
|
203
|
+
when Array
|
204
|
+
result = []
|
205
|
+
data.each do |value|
|
206
|
+
result << prefix(prefix, value)
|
207
|
+
end
|
208
|
+
|
209
|
+
when Hash
|
210
|
+
result = {}
|
211
|
+
data.each do |key, value|
|
212
|
+
result[prefix(prefix, key)] = value
|
213
|
+
end
|
214
|
+
end
|
215
|
+
return result
|
216
|
+
end
|
188
217
|
end
|
189
218
|
end
|
190
219
|
end
|
data/lib/coral_core/util/disk.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Coral
|
3
3
|
module Util
|
4
|
-
class Disk
|
4
|
+
class Disk
|
5
5
|
|
6
6
|
#-----------------------------------------------------------------------------
|
7
7
|
# Properties
|
@@ -15,7 +15,7 @@ class Disk < Core
|
|
15
15
|
# Utilities
|
16
16
|
|
17
17
|
def self.open(file_name, options = {}, reset = false)
|
18
|
-
mode =
|
18
|
+
mode = options[:mode].to_s
|
19
19
|
|
20
20
|
@@separator = ( options[:separator] ? options[:separator] : false )
|
21
21
|
@@description = ( options[:description] ? options[:description] : '' )
|
@@ -77,7 +77,12 @@ class Disk < Core
|
|
77
77
|
|
78
78
|
def self.close(file_names = [])
|
79
79
|
file_names = @@files.keys unless file_names && ! file_names.empty?
|
80
|
-
|
80
|
+
|
81
|
+
unless file_names.is_a?(Array)
|
82
|
+
file_names = [ file_names ]
|
83
|
+
end
|
84
|
+
|
85
|
+
file_names.each do |file_name|
|
81
86
|
@@files[file_name][:file].close if @@files[file_name] && @@files[file_name][:file]
|
82
87
|
@@files.delete(file_name)
|
83
88
|
end
|
data/lib/coral_core.rb
CHANGED
@@ -108,7 +108,9 @@ end
|
|
108
108
|
#---
|
109
109
|
|
110
110
|
# Include pre core utilities (no internal dependencies)
|
111
|
-
|
111
|
+
[ :data, :disk ].each do |name|
|
112
|
+
require File.join('coral_core', 'util', name.to_s + ".rb")
|
113
|
+
end
|
112
114
|
|
113
115
|
if git_location
|
114
116
|
require File.join('coral_core', 'util', 'git.rb')
|
@@ -128,7 +130,7 @@ end
|
|
128
130
|
# ( normally inherit from core and have no reverse dependencies with
|
129
131
|
# core classes )
|
130
132
|
#
|
131
|
-
[ :
|
133
|
+
[ :shell ].each do |name|
|
132
134
|
require File.join('coral_core', 'util', name.to_s + ".rb")
|
133
135
|
end
|
134
136
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coral_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 49
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 19
|
10
|
+
version: 0.2.19
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adrian Webb
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-05-
|
18
|
+
date: 2013-05-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: log4r
|