goz 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/HISTORY.rdoc +12 -0
- data/README.rdoc +33 -0
- data/Rakefile +24 -0
- data/goz.gemspec +28 -0
- data/lib/goz.rb +44 -0
- data/lib/goz/cache.rb +136 -0
- data/lib/goz/cache/hash_store.rb +75 -0
- data/lib/goz/logger.rb +141 -0
- data/lib/goz/version.rb +11 -0
- data/test/test_goz.rb +17 -0
- data/test/test_goz_cache.rb +88 -0
- data/test/test_goz_cache_hash_store.rb +40 -0
- data/test/test_goz_logger.rb +90 -0
- metadata +114 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/HISTORY.rdoc
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
= Goz - Generic self-service provisioning system
|
2
|
+
|
3
|
+
== Usage
|
4
|
+
|
5
|
+
|
6
|
+
# Cache
|
7
|
+
require 'goz/cache'
|
8
|
+
Goz::Cache.instance do |cache|
|
9
|
+
... do stuff ...
|
10
|
+
end
|
11
|
+
|
12
|
+
# Logger
|
13
|
+
require 'goz/logger'
|
14
|
+
Goz::Logger.instance('MyApp') do |logger|
|
15
|
+
... do stuff ...
|
16
|
+
end
|
17
|
+
|
18
|
+
== See Also
|
19
|
+
|
20
|
+
Goz::Cache, Goz::Logger
|
21
|
+
|
22
|
+
== Author
|
23
|
+
|
24
|
+
blair christensen. <mailto:blair.christensen@gmail.com>
|
25
|
+
|
26
|
+
== Homepage
|
27
|
+
|
28
|
+
https://github.com/blairc/goz/
|
29
|
+
|
30
|
+
== See Also
|
31
|
+
|
32
|
+
https://github.com/blairc/goz-rails/
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rdoc-readme/rake_task'
|
5
|
+
require 'rdoc/task'
|
6
|
+
|
7
|
+
%w{ coverage goz.log html out.txt pkg }.each { |p| CLEAN.include(p) }
|
8
|
+
%w{ build install rdoc test }.each { |t| task t.to_sym => [ 'rdoc:readme' ] }
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.libs << 'test'
|
14
|
+
t.test_files = FileList['test/test*.rb']
|
15
|
+
t.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
RDoc::Readme::RakeTask.new 'lib/goz.rb', 'README.rdoc'
|
19
|
+
|
20
|
+
RDoc::Task.new do |rdoc|
|
21
|
+
rdoc.main = 'README.rdoc'
|
22
|
+
rdoc.rdoc_files.include('README.rdoc', 'lib/**/*.rb', 'doc/*.txt')
|
23
|
+
end
|
24
|
+
|
data/goz.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'goz/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'goz'
|
7
|
+
s.version = Goz::VERSION
|
8
|
+
s.authors = ['blair christensen']
|
9
|
+
s.email = ['blair.christensen@gmail.com']
|
10
|
+
s.homepage = 'https://github.com/blairc/goz/'
|
11
|
+
s.summary = %q{Generic self-service provisioning system}
|
12
|
+
s.description = %q{Generic self-service provisioning system}
|
13
|
+
|
14
|
+
s.rubyforge_project = 'goz'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
s.add_development_dependency 'rdoc'
|
26
|
+
s.add_development_dependency 'rdoc-readme', '~> 0.1.2'
|
27
|
+
s.add_development_dependency 'simplecov'
|
28
|
+
end
|
data/lib/goz.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'goz/cache'
|
4
|
+
require 'goz/logger'
|
5
|
+
require 'goz/version'
|
6
|
+
|
7
|
+
#
|
8
|
+
# = Goz - Generic self-service provisioning system
|
9
|
+
#
|
10
|
+
# == Usage
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# # Cache
|
14
|
+
# require 'goz/cache'
|
15
|
+
# Goz::Cache.instance do |cache|
|
16
|
+
# ... do stuff ...
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # Logger
|
20
|
+
# require 'goz/logger'
|
21
|
+
# Goz::Logger.instance('MyApp') do |logger|
|
22
|
+
# ... do stuff ...
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# == See Also
|
26
|
+
#
|
27
|
+
# Goz::Cache, Goz::Logger
|
28
|
+
#
|
29
|
+
# == Author
|
30
|
+
#
|
31
|
+
# blair christensen. <mailto:blair.christensen@gmail.com>
|
32
|
+
#
|
33
|
+
# == Homepage
|
34
|
+
#
|
35
|
+
# https://github.com/blairc/goz/
|
36
|
+
#
|
37
|
+
# == See Also
|
38
|
+
#
|
39
|
+
# https://github.com/blairc/goz-rails/
|
40
|
+
#
|
41
|
+
module Goz
|
42
|
+
# Your code goes here...
|
43
|
+
end
|
44
|
+
|
data/lib/goz/cache.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'goz/cache/hash_store'
|
4
|
+
|
5
|
+
module Goz # :nodoc:
|
6
|
+
|
7
|
+
#
|
8
|
+
# = Goz::Cache - Generic cache
|
9
|
+
#
|
10
|
+
# == Usage
|
11
|
+
#
|
12
|
+
# require 'goz/cache'
|
13
|
+
#
|
14
|
+
# cache = Goz::Cache.new do |cache|
|
15
|
+
# # block initialization with default cache
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# cache = Goz::Cache.new(ActiveSupport::Cache::MemoryStore.new) do |cache|
|
19
|
+
# # block initialization with custom cache
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # initialization with default cache
|
23
|
+
# cache = Goz::Cache.new
|
24
|
+
#
|
25
|
+
# # initialization with custom cache
|
26
|
+
# cache = Goz::Cache.new(ActiveSupport::Cache::MemoryStore.new)
|
27
|
+
#
|
28
|
+
# # Write to cache
|
29
|
+
# cache.write(key, value)
|
30
|
+
#
|
31
|
+
# # Read from cache
|
32
|
+
# cache.read(key)
|
33
|
+
#
|
34
|
+
# # Delete from cache if key exists.
|
35
|
+
# cache.delete(key) if cache.exist?(key)
|
36
|
+
#
|
37
|
+
# # Clear the cache
|
38
|
+
# cache.clear
|
39
|
+
#
|
40
|
+
# == Author
|
41
|
+
#
|
42
|
+
# blair christensen. <mailto:blair.christensen@gmail.com>
|
43
|
+
#
|
44
|
+
# == Homepage
|
45
|
+
#
|
46
|
+
# https://github.com/blairc/goz/
|
47
|
+
#
|
48
|
+
class Cache
|
49
|
+
|
50
|
+
#
|
51
|
+
# Default cache implementation to use.
|
52
|
+
#
|
53
|
+
DEFAULT_CACHE = Goz::Cache::HashStore.new
|
54
|
+
|
55
|
+
|
56
|
+
@@caches = {}
|
57
|
+
|
58
|
+
|
59
|
+
#
|
60
|
+
# Create (if necessary) and return Goz::Cache instance.
|
61
|
+
#
|
62
|
+
# Params:
|
63
|
+
# +cache+:: (optional) Any +ActiveSupport::Cache::Store+ compatible class. Defaults to +DEFAULT_CACHE+.
|
64
|
+
#
|
65
|
+
def self.instance( cache = DEFAULT_CACHE )
|
66
|
+
unless @@caches.key?(cache)
|
67
|
+
@@caches[cache] = self.new(cache)
|
68
|
+
end
|
69
|
+
yield @@caches[cache] if block_given?
|
70
|
+
@@caches[cache]
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Initialize Goz::Cache
|
75
|
+
#
|
76
|
+
# Params:
|
77
|
+
# +cache+:: (optional) Any +ActiveSupport::Cache::Store+ compatible class. Defaults to +DEFAULT_CACHE+.
|
78
|
+
#
|
79
|
+
def initialize( cache = DEFAULT_CACHE )
|
80
|
+
@cache = cache
|
81
|
+
yield self if block_given?
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Empty cache. Returns +true+ if successful.
|
87
|
+
#
|
88
|
+
def clear
|
89
|
+
@cache.clear
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Return true if +key+ deleted from cache.
|
94
|
+
#
|
95
|
+
# Params:
|
96
|
+
# +key+:: Name of key to delete.
|
97
|
+
#
|
98
|
+
def delete(key)
|
99
|
+
@cache.delete(key)
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Return true if +key+ exists in cache.
|
104
|
+
#
|
105
|
+
# Params:
|
106
|
+
# +key+:: Name of key
|
107
|
+
#
|
108
|
+
def exist?(key)
|
109
|
+
@cache.exist?(key)
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Return value from cache or +nil+.
|
114
|
+
#
|
115
|
+
# Params:
|
116
|
+
# +key+:: Get value for this key.
|
117
|
+
#
|
118
|
+
def read(key)
|
119
|
+
@cache.read(key)
|
120
|
+
end
|
121
|
+
|
122
|
+
#
|
123
|
+
# Add +value+ to cache with +key+. Returns value added to cache.
|
124
|
+
#
|
125
|
+
# Params:
|
126
|
+
# +key+:: Associate value with this this key.
|
127
|
+
# +value+:: Value to add to cache.
|
128
|
+
#
|
129
|
+
def write(key, value)
|
130
|
+
@cache.write(key, value) ? value : nil
|
131
|
+
end
|
132
|
+
|
133
|
+
end # class Cache
|
134
|
+
|
135
|
+
end # module Goz
|
136
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Goz # :nodoc:
|
4
|
+
class Cache # :nodoc
|
5
|
+
|
6
|
+
#
|
7
|
+
# = Goz::Cache::HashStore - Hash-based cache implementation.
|
8
|
+
#
|
9
|
+
# == See Also
|
10
|
+
#
|
11
|
+
# Goz::Cache, ActiveSupport::Cache::Store
|
12
|
+
#
|
13
|
+
# == Author
|
14
|
+
#
|
15
|
+
# blair christensen. <mailto:blair.christensen@gmail.com>
|
16
|
+
#
|
17
|
+
# == Homepage
|
18
|
+
#
|
19
|
+
# https://github.com/blairc/goz/
|
20
|
+
#
|
21
|
+
class HashStore < Hash
|
22
|
+
|
23
|
+
#
|
24
|
+
# Empty cache. Returns +true+ if successful.
|
25
|
+
#
|
26
|
+
def clear
|
27
|
+
super ? true : false
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Return true if +key+ deleted from cache.
|
32
|
+
#
|
33
|
+
# Params:
|
34
|
+
# +key+:: Name of key to delete.
|
35
|
+
#
|
36
|
+
def delete(key)
|
37
|
+
super ? true : false
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Return true if +key+ exists in cache.
|
42
|
+
#
|
43
|
+
# Params:
|
44
|
+
# +key+:: Name of key
|
45
|
+
#
|
46
|
+
def exist?(key)
|
47
|
+
key?(key)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Return value from cache or +nil+.
|
52
|
+
#
|
53
|
+
# Params:
|
54
|
+
# +key+:: Get value for this key.
|
55
|
+
#
|
56
|
+
def read(key)
|
57
|
+
self[key]
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Add +value+ to cache with +key+. Returns value added to cache.
|
62
|
+
#
|
63
|
+
# Params:
|
64
|
+
# +key+:: Associate value with this this key.
|
65
|
+
# +value+:: Value to add to cache.
|
66
|
+
#
|
67
|
+
def write(key, value)
|
68
|
+
self[key] = value
|
69
|
+
end
|
70
|
+
|
71
|
+
end # class HashStore
|
72
|
+
|
73
|
+
end # class Cache
|
74
|
+
end # module Goz
|
75
|
+
|
data/lib/goz/logger.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Goz # :nodoc:
|
6
|
+
|
7
|
+
#
|
8
|
+
# = Goz::Logger - Generic logger
|
9
|
+
#
|
10
|
+
# == Usage
|
11
|
+
#
|
12
|
+
# require 'goz/logger'
|
13
|
+
#
|
14
|
+
# logger = Goz::Logger.new('MyApp') do |logger|
|
15
|
+
# logger.debug('block initialization with default logger')
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# logger = Goz::Logger.new('MyApp')
|
19
|
+
# logger.error('initialization with default logger')
|
20
|
+
#
|
21
|
+
# logger = Goz::Logger.instance( 'MyApp', ::Logger.new($stdout) ) do |logger|
|
22
|
+
# logger.fatal('instance initialization with custom logger')
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# logger = Goz::Logger.instance( 'MyApp', ::Logger.new($stdout) )
|
26
|
+
# logger.info('instance initialization with custom logger')
|
27
|
+
#
|
28
|
+
# logger.warn('warn example to cover all log severity levels')
|
29
|
+
#
|
30
|
+
# == Author
|
31
|
+
#
|
32
|
+
# blair christensen. <mailto:blair.christensen@gmail.com>
|
33
|
+
#
|
34
|
+
# == Homepage
|
35
|
+
#
|
36
|
+
# https://github.com/blairc/goz/
|
37
|
+
#
|
38
|
+
class Logger
|
39
|
+
|
40
|
+
#
|
41
|
+
# Default logfile to use.
|
42
|
+
#
|
43
|
+
DEFAULT_LOGFILE = $stdout
|
44
|
+
|
45
|
+
#
|
46
|
+
# Default logger to use.
|
47
|
+
#
|
48
|
+
DEFAULT_LOGGER = ::Logger.new(DEFAULT_LOGFILE)
|
49
|
+
|
50
|
+
|
51
|
+
@@loggers = {}
|
52
|
+
|
53
|
+
|
54
|
+
#
|
55
|
+
# Create (if necessary) and return Goz::Logger instance.
|
56
|
+
#
|
57
|
+
# Params:
|
58
|
+
# +tag+:: Tag log messages with this +String+.
|
59
|
+
# +logger+:: (optional) Any +::Logger+ compatible class. Defaults to +DEFAULT_LOGGER+.
|
60
|
+
#
|
61
|
+
def self.instance( tag, logger = DEFAULT_LOGGER )
|
62
|
+
key = [ tag, logger ]
|
63
|
+
unless @@loggers.key?(key)
|
64
|
+
@@loggers[key] = self.new(tag, logger)
|
65
|
+
end
|
66
|
+
yield @@loggers[key] if block_given?
|
67
|
+
@@loggers[key]
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Initialize Goz::Logger
|
72
|
+
#
|
73
|
+
# Params:
|
74
|
+
# +tag+:: Tag log messages with this +String+.
|
75
|
+
# +logger+:: (optional) Any +::Logger+ compatible class. Defaults to +DEFAULT_LOGGER+.
|
76
|
+
#
|
77
|
+
def initialize( tag, logger = DEFAULT_LOGGER )
|
78
|
+
@logger = logger
|
79
|
+
@tag = tag
|
80
|
+
# TODO Make configurable?
|
81
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
82
|
+
"#{datetime} #{severity} #{tag}: #{msg}\n"
|
83
|
+
end
|
84
|
+
yield self if block_given?
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Send +debug+ log message.
|
90
|
+
#
|
91
|
+
# Params:
|
92
|
+
# +message+:: +String+ message to send to logger.
|
93
|
+
#
|
94
|
+
def debug(message)
|
95
|
+
@logger.debug message
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# Send +error+ log message.
|
100
|
+
#
|
101
|
+
# Params:
|
102
|
+
# +message+:: +String+ message to send to logger.
|
103
|
+
#
|
104
|
+
def error(message)
|
105
|
+
@logger.error message
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Send +fatal+ log message.
|
110
|
+
#
|
111
|
+
# Params:
|
112
|
+
# +message+:: +String+ message to send to logger.
|
113
|
+
#
|
114
|
+
def fatal(message)
|
115
|
+
@logger.fatal message
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Send info log message.
|
120
|
+
#
|
121
|
+
# Params:
|
122
|
+
# +message+:: +String+ message to send to logger.
|
123
|
+
#
|
124
|
+
def info(message)
|
125
|
+
@logger.info message
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Send warn log message.
|
130
|
+
#
|
131
|
+
# Params:
|
132
|
+
# +message+:: +String+ message to send to logger.
|
133
|
+
#
|
134
|
+
def warn(message)
|
135
|
+
@logger.warn message
|
136
|
+
end
|
137
|
+
|
138
|
+
end # class Logger
|
139
|
+
|
140
|
+
end # module Goz
|
141
|
+
|
data/lib/goz/version.rb
ADDED
data/test/test_goz.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'goz/cache'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
|
10
|
+
class TestGozCache < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@cache = Goz::Cache.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_default_initialization
|
17
|
+
blockable = false
|
18
|
+
cache = Goz::Cache.new do |cache|
|
19
|
+
assert_kind_of Goz::Cache, cache
|
20
|
+
blockable = true
|
21
|
+
end
|
22
|
+
assert blockable, 'works as block'
|
23
|
+
assert_kind_of Goz::Cache, cache
|
24
|
+
assert_kind_of Goz::Cache, Goz::Cache.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialization
|
28
|
+
blockable = false
|
29
|
+
cache = Goz::Cache.new(@cache) do |cache|
|
30
|
+
assert_kind_of Goz::Cache, cache
|
31
|
+
blockable = true
|
32
|
+
end
|
33
|
+
assert blockable, 'works as block'
|
34
|
+
assert_kind_of Goz::Cache, cache
|
35
|
+
assert_kind_of Goz::Cache, Goz::Cache.new(@cache)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_default_instance
|
39
|
+
blockable = false
|
40
|
+
cache = Goz::Cache.instance do |cache|
|
41
|
+
assert_kind_of Goz::Cache, cache
|
42
|
+
blockable = true
|
43
|
+
end
|
44
|
+
assert blockable, 'works as block'
|
45
|
+
assert_kind_of Goz::Cache, cache
|
46
|
+
assert_kind_of Goz::Cache, Goz::Cache.instance
|
47
|
+
assert_equal cache, Goz::Cache.instance
|
48
|
+
assert_not_equal cache, Goz::Cache.instance(Array.new)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_instance
|
52
|
+
blockable = false
|
53
|
+
cache = Goz::Cache.instance(@cache) do |cache|
|
54
|
+
assert_kind_of Goz::Cache, cache
|
55
|
+
blockable = true
|
56
|
+
end
|
57
|
+
assert blockable, 'works as block'
|
58
|
+
assert_kind_of Goz::Cache, cache
|
59
|
+
assert_kind_of Goz::Cache, Goz::Cache.instance(@cache)
|
60
|
+
assert_equal cache, Goz::Cache.instance(@cache)
|
61
|
+
assert_not_equal cache, Goz::Cache.instance(Array.new)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_default_cache
|
65
|
+
assert_kind_of Goz::Cache::HashStore, Goz::Cache::DEFAULT_CACHE
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_caching
|
69
|
+
key, value = :foo, :bar
|
70
|
+
|
71
|
+
assert_equal false, @cache.exist?(key)
|
72
|
+
assert_equal false, @cache.delete(key)
|
73
|
+
|
74
|
+
assert_equal value, @cache.write(key, value)
|
75
|
+
assert_equal value, @cache.read(key)
|
76
|
+
assert_equal true, @cache.exist?(key)
|
77
|
+
assert_equal true, @cache.delete(key)
|
78
|
+
assert_equal false, @cache.exist?(key)
|
79
|
+
assert_equal nil, @cache.read(key)
|
80
|
+
|
81
|
+
assert_equal value, @cache.write(key, value)
|
82
|
+
assert_equal true, @cache.exist?(key)
|
83
|
+
assert_equal true, @cache.clear
|
84
|
+
assert_equal false, @cache.exist?(key)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'goz/cache/hash_store'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
|
10
|
+
class TestGozCacheHashStore < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@cache = Goz::Cache::HashStore.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_default_initialization
|
17
|
+
assert_kind_of Goz::Cache::HashStore, @cache
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_caching
|
21
|
+
key, value = :foo, :bar
|
22
|
+
|
23
|
+
assert_equal false, @cache.exist?(key)
|
24
|
+
assert_equal false, @cache.delete(key)
|
25
|
+
|
26
|
+
assert_equal value, @cache.write(key, value)
|
27
|
+
assert_equal value, @cache.read(key)
|
28
|
+
assert_equal true, @cache.exist?(key)
|
29
|
+
assert_equal true, @cache.delete(key)
|
30
|
+
assert_equal false, @cache.exist?(key)
|
31
|
+
assert_equal nil, @cache.read(key)
|
32
|
+
|
33
|
+
assert_equal value, @cache.write(key, value)
|
34
|
+
assert_equal true, @cache.exist?(key)
|
35
|
+
assert_equal true, @cache.clear
|
36
|
+
assert_equal false, @cache.exist?(key)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'goz/logger'
|
7
|
+
require 'logger'
|
8
|
+
require 'stringio'
|
9
|
+
require 'test/unit'
|
10
|
+
|
11
|
+
|
12
|
+
class TestGozLogger < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@s = StringIO.new
|
16
|
+
@logger = Logger.new(@s)
|
17
|
+
@tag = self.class.name
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_default_initialization
|
21
|
+
blockable = false
|
22
|
+
logger = Goz::Logger.new(@tag) do |logger|
|
23
|
+
assert_kind_of Goz::Logger, logger
|
24
|
+
blockable = true
|
25
|
+
end
|
26
|
+
assert blockable, 'works as block'
|
27
|
+
assert_kind_of Goz::Logger, logger
|
28
|
+
assert_kind_of Goz::Logger, Goz::Logger.new(@tag)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_initialization
|
32
|
+
blockable = false
|
33
|
+
logger = Goz::Logger.new(@tag, @logger) do |logger|
|
34
|
+
assert_kind_of Goz::Logger, logger
|
35
|
+
blockable = true
|
36
|
+
end
|
37
|
+
assert blockable, 'works as block'
|
38
|
+
assert_kind_of Goz::Logger, logger
|
39
|
+
assert_kind_of Goz::Logger, Goz::Logger.new(@tag, @logger)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_default_instance
|
43
|
+
blockable = false
|
44
|
+
logger = Goz::Logger.instance(@tag) do |logger|
|
45
|
+
assert_kind_of Goz::Logger, logger
|
46
|
+
blockable = true
|
47
|
+
end
|
48
|
+
assert blockable, 'works as block'
|
49
|
+
assert_kind_of Goz::Logger, logger
|
50
|
+
assert_kind_of Goz::Logger, Goz::Logger.instance(@tag)
|
51
|
+
assert_equal logger, Goz::Logger.instance(@tag)
|
52
|
+
assert_not_equal logger, Goz::Logger.instance('foo')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_instance
|
56
|
+
blockable = false
|
57
|
+
logger = Goz::Logger.instance(@tag, @logger) do |logger|
|
58
|
+
assert_kind_of Goz::Logger, logger
|
59
|
+
blockable = true
|
60
|
+
end
|
61
|
+
assert blockable, 'works as block'
|
62
|
+
assert_kind_of Goz::Logger, logger
|
63
|
+
assert_kind_of Goz::Logger, Goz::Logger.instance(@tag, @logger)
|
64
|
+
assert_equal logger, Goz::Logger.instance(@tag, @logger)
|
65
|
+
assert_not_equal logger, Goz::Logger.instance('foo')
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_logging_within_block
|
69
|
+
[ :debug, :error, :fatal, :info, :warn ].each do |severity|
|
70
|
+
Goz::Logger.new(@tag, @logger) do |logger|
|
71
|
+
logger.send severity, "this is a #{ severity.to_s } message"
|
72
|
+
@s.rewind
|
73
|
+
rx = %r{^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2} [+-]\d+ #{ severity.to_s.upcase } #{ @tag }: this is a #{ severity.to_s } message$}
|
74
|
+
assert_match rx, @s.readlines.last.chomp
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_logging_outside_of_block
|
80
|
+
[ :debug, :error, :fatal, :info, :warn ].each do |severity|
|
81
|
+
logger = Goz::Logger.new(@tag, @logger)
|
82
|
+
logger.send severity, "this is a #{ severity.to_s } message"
|
83
|
+
@s.rewind
|
84
|
+
rx = %r{^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2} [+-]\d+ #{ severity.to_s.upcase } #{ @tag }: this is a #{ severity.to_s } message$}
|
85
|
+
assert_match rx, @s.readlines.join.chomp
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- blair christensen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-08 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70286441430580 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70286441430580
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rdoc
|
27
|
+
requirement: &70286441430140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70286441430140
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc-readme
|
38
|
+
requirement: &70286441429640 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.1.2
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70286441429640
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: simplecov
|
49
|
+
requirement: &70286441429220 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70286441429220
|
58
|
+
description: Generic self-service provisioning system
|
59
|
+
email:
|
60
|
+
- blair.christensen@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- Gemfile
|
67
|
+
- HISTORY.rdoc
|
68
|
+
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- goz.gemspec
|
71
|
+
- lib/goz.rb
|
72
|
+
- lib/goz/cache.rb
|
73
|
+
- lib/goz/cache/hash_store.rb
|
74
|
+
- lib/goz/logger.rb
|
75
|
+
- lib/goz/version.rb
|
76
|
+
- test/test_goz.rb
|
77
|
+
- test/test_goz_cache.rb
|
78
|
+
- test/test_goz_cache_hash_store.rb
|
79
|
+
- test/test_goz_logger.rb
|
80
|
+
homepage: https://github.com/blairc/goz/
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
hash: -4339046031995261735
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: -4339046031995261735
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project: goz
|
106
|
+
rubygems_version: 1.8.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Generic self-service provisioning system
|
110
|
+
test_files:
|
111
|
+
- test/test_goz.rb
|
112
|
+
- test/test_goz_cache.rb
|
113
|
+
- test/test_goz_cache_hash_store.rb
|
114
|
+
- test/test_goz_logger.rb
|