toystore 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/toy.rb +20 -1
- data/lib/toy/logger.rb +5 -2
- data/lib/toy/store.rb +0 -2
- data/lib/toy/validations.rb +1 -1
- data/lib/toy/version.rb +1 -1
- data/spec/toy/dolly_spec.rb +1 -1
- data/spec/toy/logger_spec.rb +20 -2
- data/spec/toy_spec.rb +29 -0
- metadata +4 -7
- data/lib/toy/connection.rb +0 -28
- data/spec/toy/connection_spec.rb +0 -47
data/lib/toy.rb
CHANGED
@@ -42,13 +42,32 @@ module Toy
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def logger
|
46
|
+
@logger
|
47
|
+
end
|
48
|
+
|
49
|
+
def logger?
|
50
|
+
@logger.present?
|
51
|
+
end
|
52
|
+
|
53
|
+
def logger=(logger)
|
54
|
+
@logger = logger
|
55
|
+
end
|
56
|
+
|
57
|
+
def key_factory=(key_factory)
|
58
|
+
@key_factory = key_factory
|
59
|
+
end
|
60
|
+
|
61
|
+
def key_factory
|
62
|
+
@key_factory ||= Toy::Identity::UUIDKeyFactory.new
|
63
|
+
end
|
64
|
+
|
45
65
|
module Middleware
|
46
66
|
autoload 'IdentityMap', 'toy/middleware/identity_map'
|
47
67
|
end
|
48
68
|
end
|
49
69
|
|
50
70
|
require 'toy/exceptions'
|
51
|
-
require 'toy/connection'
|
52
71
|
require 'toy/attribute'
|
53
72
|
require 'toy/attributes'
|
54
73
|
require 'toy/callbacks'
|
data/lib/toy/logger.rb
CHANGED
@@ -3,13 +3,16 @@ module Toy
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
+
OperationsToLogValueFor = [:get, :set, :del]
|
7
|
+
|
6
8
|
def logger
|
7
9
|
Toy.logger
|
8
10
|
end
|
9
11
|
|
10
12
|
def log_operation(operation, model, adapter, key, value=nil)
|
11
|
-
if logger.debug?
|
12
|
-
logger.debug("
|
13
|
+
if logger && logger.debug?
|
14
|
+
logger.debug("TOYSTORE #{operation.to_s.upcase} #{model} :#{adapter.name} #{key.inspect}")
|
15
|
+
logger.debug(" #{value.inspect}") if !value.nil? && OperationsToLogValueFor.include?(operation)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
data/lib/toy/store.rb
CHANGED
data/lib/toy/validations.rb
CHANGED
data/lib/toy/version.rb
CHANGED
data/spec/toy/dolly_spec.rb
CHANGED
data/spec/toy/logger_spec.rb
CHANGED
@@ -3,6 +3,14 @@ require 'helper'
|
|
3
3
|
describe Toy::Logger do
|
4
4
|
uses_constants('User')
|
5
5
|
|
6
|
+
before do
|
7
|
+
@logger = Toy.logger
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
Toy.logger = @logger
|
12
|
+
end
|
13
|
+
|
6
14
|
it "should use Toy.logger for class" do
|
7
15
|
User.logger.should == Toy.logger
|
8
16
|
end
|
@@ -15,16 +23,26 @@ describe Toy::Logger do
|
|
15
23
|
let(:adapter) { Adapter[:memory].new({}) }
|
16
24
|
|
17
25
|
it "logs operation" do
|
18
|
-
|
26
|
+
Toy.logger = stub(:debug? => true)
|
27
|
+
User.logger.should_receive(:debug).with('TOYSTORE GET User :memory "foo"')
|
28
|
+
User.logger.should_receive(:debug).with(' "bar"')
|
19
29
|
User.log_operation(:get, User, adapter, 'foo', 'bar')
|
20
30
|
end
|
31
|
+
|
32
|
+
it "ignores operations that should not be logged" do
|
33
|
+
Toy.logger = stub(:debug? => true)
|
34
|
+
User.logger.should_receive(:debug).with('TOYSTORE IMG User :memory "foo"')
|
35
|
+
User.log_operation(:img, User, adapter, 'foo', 'bar')
|
36
|
+
end
|
21
37
|
end
|
22
38
|
|
23
39
|
describe "#log_operation" do
|
24
40
|
let(:adapter) { Adapter[:memory].new({}) }
|
25
41
|
|
26
42
|
it "logs operation" do
|
27
|
-
|
43
|
+
Toy.logger = stub(:debug? => true)
|
44
|
+
User.logger.should_receive(:debug).with('TOYSTORE GET User :memory "foo"')
|
45
|
+
User.logger.should_receive(:debug).with(' "bar"')
|
28
46
|
User.log_operation(:get, User, adapter, 'foo', 'bar')
|
29
47
|
end
|
30
48
|
end
|
data/spec/toy_spec.rb
CHANGED
@@ -18,4 +18,33 @@ describe Toy do
|
|
18
18
|
lambda { Toy.clear }.should_not raise_error
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe ".logger" do
|
23
|
+
before do
|
24
|
+
@logger = Toy.logger
|
25
|
+
end
|
26
|
+
|
27
|
+
after do
|
28
|
+
Toy.logger = @logger
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set the default logger" do
|
32
|
+
logger = stub
|
33
|
+
Toy.logger = logger
|
34
|
+
Toy.logger.should == logger
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".key_factory" do
|
39
|
+
it "should set the default key_factory" do
|
40
|
+
key_factory = stub
|
41
|
+
Toy.key_factory = key_factory
|
42
|
+
Toy.key_factory.should == key_factory
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should default to the UUIDKeyFactory" do
|
46
|
+
Toy.key_factory = nil
|
47
|
+
Toy.key_factory.should be_instance_of(Toy::Identity::UUIDKeyFactory)
|
48
|
+
end
|
49
|
+
end
|
21
50
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toystore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 2
|
10
|
+
version: 0.8.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Geoffrey Dagley
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-07-
|
19
|
+
date: 2011-07-05 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: adapter
|
@@ -114,7 +114,6 @@ files:
|
|
114
114
|
- lib/toy/caching.rb
|
115
115
|
- lib/toy/callbacks.rb
|
116
116
|
- lib/toy/collection.rb
|
117
|
-
- lib/toy/connection.rb
|
118
117
|
- lib/toy/dirty.rb
|
119
118
|
- lib/toy/dolly.rb
|
120
119
|
- lib/toy/embedded_list.rb
|
@@ -169,7 +168,6 @@ files:
|
|
169
168
|
- spec/toy/attributes_spec.rb
|
170
169
|
- spec/toy/caching_spec.rb
|
171
170
|
- spec/toy/callbacks_spec.rb
|
172
|
-
- spec/toy/connection_spec.rb
|
173
171
|
- spec/toy/dirty_spec.rb
|
174
172
|
- spec/toy/dolly_spec.rb
|
175
173
|
- spec/toy/embedded_list_spec.rb
|
@@ -254,7 +252,6 @@ test_files:
|
|
254
252
|
- spec/toy/attributes_spec.rb
|
255
253
|
- spec/toy/caching_spec.rb
|
256
254
|
- spec/toy/callbacks_spec.rb
|
257
|
-
- spec/toy/connection_spec.rb
|
258
255
|
- spec/toy/dirty_spec.rb
|
259
256
|
- spec/toy/dolly_spec.rb
|
260
257
|
- spec/toy/embedded_list_spec.rb
|
data/lib/toy/connection.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Toy
|
2
|
-
module Connection
|
3
|
-
def logger
|
4
|
-
@@logger ||= init_default_logger
|
5
|
-
end
|
6
|
-
|
7
|
-
def logger=(logger)
|
8
|
-
@@logger = logger
|
9
|
-
end
|
10
|
-
|
11
|
-
def key_factory=(key_factory)
|
12
|
-
@@key_factory = key_factory
|
13
|
-
end
|
14
|
-
|
15
|
-
def key_factory
|
16
|
-
@@key_factory ||= Toy::Identity::UUIDKeyFactory.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def init_default_logger
|
20
|
-
if Object.const_defined?("RAILS_DEFAULT_LOGGER")
|
21
|
-
@@logger = Object.const_get("RAILS_DEFAULT_LOGGER")
|
22
|
-
else
|
23
|
-
require 'logger'
|
24
|
-
@@logger = ::Logger.new(STDOUT)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/spec/toy/connection_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Toy::Connection do
|
4
|
-
uses_constants('User')
|
5
|
-
|
6
|
-
before do
|
7
|
-
@logger = Toy.logger
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
Toy.logger = @logger
|
12
|
-
end
|
13
|
-
|
14
|
-
describe ".logger" do
|
15
|
-
it "should set the default logger" do
|
16
|
-
logger = stub
|
17
|
-
Toy.logger = logger
|
18
|
-
Toy.logger.should == logger
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should be an instance of Logger if not set" do
|
22
|
-
Toy.logger = nil
|
23
|
-
Toy.logger.should be_instance_of(Logger)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should use RAILS_DEFAULT_LOGGER if defined" do
|
27
|
-
remove_constants("RAILS_DEFAULT_LOGGER")
|
28
|
-
RAILS_DEFAULT_LOGGER = stub
|
29
|
-
|
30
|
-
Toy.logger = nil
|
31
|
-
Toy.logger.should == RAILS_DEFAULT_LOGGER
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".key_factory" do
|
36
|
-
it "should set the default key_factory" do
|
37
|
-
key_factory = stub
|
38
|
-
Toy.key_factory = key_factory
|
39
|
-
Toy.key_factory.should == key_factory
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should default to the UUIDKeyFactory" do
|
43
|
-
Toy.key_factory = nil
|
44
|
-
Toy.key_factory.should be_instance_of(Toy::Identity::UUIDKeyFactory)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|