ccp 0.3.0 → 0.3.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.
- data/ccp.gemspec +1 -1
- data/lib/ccp/commands/fixturable.rb +1 -1
- data/lib/ccp/kvs/core.rb +1 -0
- data/lib/ccp/kvs/tokyo/state_machine.rb +1 -0
- data/lib/ccp/storage.rb +2 -2
- data/lib/ccp/utils/colorize.rb +61 -9
- data/lib/ccp/version.rb +1 -1
- data/spec/storage/loadable_spec.rb +9 -1
- data/spec/utils/colorize_spec.rb +56 -0
- metadata +9 -8
data/ccp.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
end
|
27
27
|
|
28
28
|
s.add_dependency "typed", ">= 0.2.2"
|
29
|
-
s.add_dependency "must", ">= 0.
|
29
|
+
s.add_dependency "must", ">= 0.3.0"
|
30
30
|
s.add_dependency "dsl_accessor", ">= 0.4.1"
|
31
31
|
s.add_dependency "json"
|
32
32
|
s.add_dependency "yajl-ruby"
|
@@ -7,7 +7,7 @@ module Ccp
|
|
7
7
|
dsl_accessor :fixture, options(:stub, :mock, :fail, :save, :keys, :dir, :kvs, :ext)
|
8
8
|
|
9
9
|
def self.test(options = {})
|
10
|
-
execute({:fixture_test=>true}.merge(options))
|
10
|
+
execute({:fixture_test=>true,:logger=>Logger.new(STDOUT)}.merge(options))
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/ccp/kvs/core.rb
CHANGED
@@ -18,6 +18,7 @@ module Ccp
|
|
18
18
|
def put(k,v) ; set(k,v) ; end
|
19
19
|
def out(k) ; del(k) ; end
|
20
20
|
|
21
|
+
def codec ; @codec ; end
|
21
22
|
def codec!(c); @codec = Ccp::Serializers[c] ; self ; end
|
22
23
|
def encode(v); @codec ? @codec.encode(v) : v ; end
|
23
24
|
def decode(v); (v && @codec) ? @codec.decode(v) : v ; end
|
@@ -64,6 +64,7 @@ module Ccp
|
|
64
64
|
case state
|
65
65
|
when CLOSED ; begin; W!(); yield; ensure; close; end
|
66
66
|
when READABLE ; raise "reopen from read to write is not permitted"
|
67
|
+
# TODO: close -> W -> close -> R ???
|
67
68
|
when WRITABLE ; yield
|
68
69
|
else ; raise "unknown state: #{state}"
|
69
70
|
end
|
data/lib/ccp/storage.rb
CHANGED
@@ -3,7 +3,7 @@ module Ccp
|
|
3
3
|
NotFound = Class.new(RuntimeError)
|
4
4
|
|
5
5
|
def self.load(path)
|
6
|
-
array = path.split(".")
|
6
|
+
array = path.to_s.split(".")
|
7
7
|
kvs = Ccp::Kvs[array.pop]
|
8
8
|
codec = Ccp::Serializers[array.pop]
|
9
9
|
return new(path, kvs, codec)
|
@@ -39,7 +39,7 @@ module Ccp
|
|
39
39
|
def table(name, file = nil)
|
40
40
|
@tables[name.to_s] ||= (
|
41
41
|
file ||= "%s.%s.%s" % [name, @codec.ext, @kvs.ext]
|
42
|
-
|
42
|
+
@kvs.class.new((@path + file).to_s).codec!(@codec)
|
43
43
|
)
|
44
44
|
end
|
45
45
|
|
data/lib/ccp/utils/colorize.rb
CHANGED
@@ -1,15 +1,67 @@
|
|
1
1
|
module Ccp
|
2
2
|
module Utils
|
3
3
|
module Colorize
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
# [examples]
|
5
|
+
# Ccp::Utils::Colorize::Fore.red("hello")
|
6
|
+
# Ccp::Utils::Colorize::Back.red("hello")
|
7
|
+
# Ccp::Utils::Colorize.red("hello") # same as Fore
|
8
|
+
|
9
|
+
module Fore
|
10
|
+
CLEAR = "\e[0m"
|
11
|
+
BLACK = "\e[30m"
|
12
|
+
RED = "\e[31m"
|
13
|
+
GREEN = "\e[32m"
|
14
|
+
YELLOW = "\e[33m"
|
15
|
+
BLUE = "\e[34m"
|
16
|
+
MAGENTA = "\e[35m"
|
17
|
+
CYAN = "\e[36m"
|
18
|
+
WHITE = "\e[37m"
|
19
|
+
|
20
|
+
def colorize(text, code); code + text.to_s + CLEAR; end
|
21
|
+
|
22
|
+
def black (text) BLACK + text.to_s + CLEAR; end
|
23
|
+
def red (text) RED + text.to_s + CLEAR; end
|
24
|
+
def green (text) GREEN + text.to_s + CLEAR; end
|
25
|
+
def yellow (text) YELLOW + text.to_s + CLEAR; end
|
26
|
+
def blue (text) BLUE + text.to_s + CLEAR; end
|
27
|
+
def magenta(text) MAGENTA + text.to_s + CLEAR; end
|
28
|
+
def purple (text) MAGENTA + text.to_s + CLEAR; end # alias
|
29
|
+
def pink (text) MAGENTA + text.to_s + CLEAR; end # alias
|
30
|
+
def cyan (text) CYAN + text.to_s + CLEAR; end
|
31
|
+
def aqua (text) CYAN + text.to_s + CLEAR; end # alias
|
32
|
+
def white (text) WHITE + text.to_s + CLEAR; end
|
33
|
+
extend self
|
34
|
+
end
|
35
|
+
|
36
|
+
module Back
|
37
|
+
CLEAR = "\e[0m"
|
38
|
+
BLACK = "\e[40m"
|
39
|
+
RED = "\e[41m"
|
40
|
+
GREEN = "\e[42m"
|
41
|
+
YELLOW = "\e[43m"
|
42
|
+
BLUE = "\e[44m"
|
43
|
+
MAGENTA = "\e[45m"
|
44
|
+
CYAN = "\e[46m"
|
45
|
+
WHITE = "\e[47m"
|
46
|
+
|
47
|
+
def colorize(text, code); code + text.to_s + CLEAR; end
|
48
|
+
|
49
|
+
def black (text) BLACK + text.to_s + CLEAR; end
|
50
|
+
def red (text) RED + text.to_s + CLEAR; end
|
51
|
+
def green (text) GREEN + text.to_s + CLEAR; end
|
52
|
+
def yellow (text) YELLOW + text.to_s + CLEAR; end
|
53
|
+
def blue (text) BLUE + text.to_s + CLEAR; end
|
54
|
+
def magenta(text) MAGENTA + text.to_s + CLEAR; end
|
55
|
+
def purple (text) MAGENTA + text.to_s + CLEAR; end # alias
|
56
|
+
def pink (text) MAGENTA + text.to_s + CLEAR; end # alias
|
57
|
+
def cyan (text) CYAN + text.to_s + CLEAR; end
|
58
|
+
def aqua (text) CYAN + text.to_s + CLEAR; end # alias
|
59
|
+
def white (text) WHITE + text.to_s + CLEAR; end
|
60
|
+
extend self
|
61
|
+
end
|
62
|
+
|
63
|
+
include Fore
|
64
|
+
extend Fore
|
13
65
|
end
|
14
66
|
end
|
15
67
|
end
|
data/lib/ccp/version.rb
CHANGED
@@ -9,14 +9,15 @@ describe Ccp::Storage do
|
|
9
9
|
describe ".load" do
|
10
10
|
context "('tmp/foo.json.tch')" do
|
11
11
|
subject { Ccp::Storage.load('tmp/foo.json.tch') }
|
12
|
+
it { should be_kind_of(Ccp::Storage) }
|
12
13
|
its(:source) { should == 'tmp/foo.json.tch' }
|
13
14
|
its(:kvs) { should be_kind_of(Ccp::Kvs::Tch) }
|
14
15
|
its(:codec) { should == Ccp::Serializers::Json }
|
15
16
|
|
16
17
|
describe "table(:foo)" do
|
17
18
|
subject { Ccp::Storage.load('tmp/foo.json.tch').table(:bar) }
|
19
|
+
it { should be_kind_of(Ccp::Kvs::Tch) }
|
18
20
|
its(:source) { should == 'tmp/foo.json.tch/bar.json.tch' }
|
19
|
-
its(:kvs) { should be_kind_of(Ccp::Kvs::Tch) }
|
20
21
|
its(:codec) { should == Ccp::Serializers::Json }
|
21
22
|
end
|
22
23
|
end
|
@@ -27,6 +28,13 @@ describe Ccp::Storage do
|
|
27
28
|
its(:kvs) { should be_kind_of(Ccp::Kvs::Tch) }
|
28
29
|
its(:codec) { should == Ccp::Serializers::Msgpack }
|
29
30
|
end
|
31
|
+
|
32
|
+
context "(pathname)" do
|
33
|
+
subject { Ccp::Storage.load(Pathname('tmp/foo.msgpack.tch')) }
|
34
|
+
its(:source) { should == Pathname('tmp/foo.msgpack.tch') }
|
35
|
+
its(:kvs) { should be_kind_of(Ccp::Kvs::Tch) }
|
36
|
+
its(:codec) { should == Ccp::Serializers::Msgpack }
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
describe "#read!" do
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Ccp::Utils::Colorize do
|
5
|
+
let(:text) { "hello" }
|
6
|
+
|
7
|
+
subject {
|
8
|
+
# methods
|
9
|
+
object.black(text) .should be_kind_of(String)
|
10
|
+
object.red(text) .should be_kind_of(String)
|
11
|
+
object.green(text) .should be_kind_of(String)
|
12
|
+
object.yellow(text) .should be_kind_of(String)
|
13
|
+
object.blue(text) .should be_kind_of(String)
|
14
|
+
object.magenta(text).should be_kind_of(String)
|
15
|
+
object.purple(text) .should be_kind_of(String)
|
16
|
+
object.pink(text) .should be_kind_of(String)
|
17
|
+
object.cyan(text) .should be_kind_of(String)
|
18
|
+
object.aqua(text) .should be_kind_of(String)
|
19
|
+
object.white(text) .should be_kind_of(String)
|
20
|
+
|
21
|
+
# alias
|
22
|
+
object.purple(text).should == object.magenta(text)
|
23
|
+
object.pink(text) .should == object.magenta(text)
|
24
|
+
object.aqua(text) .should == object.cyan(text)
|
25
|
+
}
|
26
|
+
|
27
|
+
context "(static)" do
|
28
|
+
subject { Ccp::Utils::Colorize }
|
29
|
+
it { should be }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "(include)" do
|
33
|
+
subject { Object.new.extend(Ccp::Utils::Colorize) }
|
34
|
+
it { should be }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "(fore)" do
|
38
|
+
subject { Ccp::Utils::Colorize::Fore }
|
39
|
+
it { should be }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "(fore include)" do
|
43
|
+
subject { Object.new.extend(Ccp::Utils::Colorize::Fore) }
|
44
|
+
it { should be }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "(back)" do
|
48
|
+
subject { Ccp::Utils::Colorize::Back }
|
49
|
+
it { should be }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "(back include)" do
|
53
|
+
subject { Object.new.extend(Ccp::Utils::Colorize::Back) }
|
54
|
+
it { should be }
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ccp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- maiha
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-08-
|
18
|
+
date: 2013-08-26 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activesupport
|
@@ -57,12 +57,12 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 19
|
61
61
|
segments:
|
62
62
|
- 0
|
63
|
-
-
|
64
|
-
-
|
65
|
-
version: 0.
|
63
|
+
- 3
|
64
|
+
- 0
|
65
|
+
version: 0.3.0
|
66
66
|
type: :runtime
|
67
67
|
version_requirements: *id003
|
68
68
|
- !ruby/object:Gem::Dependency
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- spec/serializers/serializer_spec.rb
|
266
266
|
- spec/spec_helper.rb
|
267
267
|
- spec/storage/loadable_spec.rb
|
268
|
+
- spec/utils/colorize_spec.rb
|
268
269
|
homepage: http://github.com/maiha/ccp
|
269
270
|
licenses:
|
270
271
|
- MIT
|