cistern 2.0.2 → 2.0.3
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 +4 -4
- data/README.md +5 -6
- data/lib/cistern/formatter.rb +4 -0
- data/lib/cistern/formatter/default.rb +22 -0
- data/lib/cistern/model.rb +1 -5
- data/lib/cistern/version.rb +1 -1
- data/spec/formatter_spec.rb +57 -29
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62a24a469ced62056ea61f768a991144ea7dad32
|
4
|
+
data.tar.gz: 30ca44a90ed296c9018078bf7e7ea4ee47e0925f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6099df1553e5ffe2545dacf6b5b0ed30962aa8a34fa5411c657e6346cf38a129d8905d2d49e8b1eb64ef105acaccdb04013acd5791e9e4e8899305a7864a333
|
7
|
+
data.tar.gz: ea06d0083d50711092a437b8a3af93de9ee947138c273670a45553690d2c4944214a5d2e93e778fefaead17744f9688f41333cf8de0cc1318453c23df35dec43
|
data/README.md
CHANGED
@@ -11,9 +11,9 @@ Cistern helps you consistently build your API clients and faciliates building mo
|
|
11
11
|
|
12
12
|
### Service
|
13
13
|
|
14
|
-
This represents the remote service that you are wrapping. If the service name is
|
14
|
+
This represents the remote service that you are wrapping. If the service name is `foo` then a good name is `Foo::Client`.
|
15
15
|
|
16
|
-
Service initialization parameters are enumerated by `requires` and `recognizes`.
|
16
|
+
Service initialization parameters are enumerated by `requires` and `recognizes`. Parameters defined using `recognizes` are optional.
|
17
17
|
|
18
18
|
```ruby
|
19
19
|
class Foo::Client < Cistern::Service
|
@@ -34,7 +34,7 @@ Cistern will define for you two classes, `Mock` and `Real`.
|
|
34
34
|
|
35
35
|
### Mocking
|
36
36
|
|
37
|
-
Cistern strongly encourages you to generate mock support for service. Mocking can be enabled using `mock!`.
|
37
|
+
Cistern strongly encourages you to generate mock support for your service. Mocking can be enabled using `mock!`.
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
Foo::Client.mocking? # falsey
|
@@ -70,7 +70,7 @@ end
|
|
70
70
|
Foo::Client.new.get_bar # "i'm real"
|
71
71
|
```
|
72
72
|
|
73
|
-
The `#service_method` function allows you to
|
73
|
+
The `#service_method` function allows you to specify the name of the generated method.
|
74
74
|
|
75
75
|
```ruby
|
76
76
|
class Foo::Client::GetBars < Foo::Client::Request
|
@@ -224,8 +224,7 @@ client.data["bars"] += ["y"] # ["y"]
|
|
224
224
|
client.data.object_id # 70199868378300
|
225
225
|
client.clear
|
226
226
|
client.data["bars"] # []
|
227
|
-
|
228
|
-
client.data.object_id # 70199868566840
|
227
|
+
client.data.object_id # 70199868378300
|
229
228
|
```
|
230
229
|
|
231
230
|
* `store` and `[]=` write
|
data/lib/cistern/formatter.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Cistern::Formatter::Default
|
2
|
+
class << self
|
3
|
+
def call(object)
|
4
|
+
case object
|
5
|
+
when Cistern::Collection
|
6
|
+
format_collection(object)
|
7
|
+
when Cistern::Model
|
8
|
+
format_model(object)
|
9
|
+
else
|
10
|
+
object.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def format_model(model)
|
15
|
+
"#{model.to_s} #{model.attributes.inspect}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def format_collection(collection)
|
19
|
+
"#{collection.to_s} #{collection.attributes.inspect} records=[#{collection.records.map { |m| format_model(m) }.join(", ")}]"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/cistern/model.rb
CHANGED
@@ -24,11 +24,7 @@ module Cistern::Model
|
|
24
24
|
attr_accessor :collection, :service
|
25
25
|
|
26
26
|
def inspect
|
27
|
-
|
28
|
-
Cistern.formatter.call(self)
|
29
|
-
else
|
30
|
-
"#<#{self.class} #{self.identity}"
|
31
|
-
end
|
27
|
+
Cistern.formatter.call(self)
|
32
28
|
end
|
33
29
|
|
34
30
|
def initialize(attributes={})
|
data/lib/cistern/version.rb
CHANGED
data/spec/formatter_spec.rb
CHANGED
@@ -1,41 +1,75 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class Inspector < Sample::Model
|
4
|
+
identity :id
|
5
|
+
attribute :name
|
6
|
+
end
|
7
|
+
|
8
|
+
class Anon < Sample::Model
|
9
|
+
attribute :chan
|
10
|
+
end
|
11
|
+
|
12
|
+
class Inspectors < Sample::Collection
|
13
|
+
model Inspector
|
14
|
+
|
15
|
+
def all(options={})
|
16
|
+
merge_attributes(options)
|
17
|
+
self.load([{id: 1, name: "2"},{id: 3, name: "4"}])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Cistern::Formatter::Default do
|
22
|
+
before { Cistern.formatter = described_class }
|
23
|
+
|
24
|
+
it "formats a model" do
|
25
|
+
expect(
|
26
|
+
Inspector.new(id: 1, name: "name").inspect
|
27
|
+
).to match(
|
28
|
+
/<Inspector:0x[a-z0-9]+> {:id=>1, :name=>\"name\"}/
|
29
|
+
)
|
30
|
+
|
31
|
+
Anon.inspect
|
32
|
+
end
|
33
|
+
|
34
|
+
it "formats a collection" do
|
35
|
+
expect(
|
36
|
+
Inspectors.new.all.inspect
|
37
|
+
).to match(
|
38
|
+
/<Inspectors:0x[a-z0-9]+> {} records/
|
39
|
+
)
|
7
40
|
end
|
41
|
+
end
|
8
42
|
|
9
|
-
|
10
|
-
|
43
|
+
describe Cistern::Formatter::AwesomePrint do
|
44
|
+
before { Cistern.formatter = described_class }
|
11
45
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
46
|
+
it "formats a model" do
|
47
|
+
expect(
|
48
|
+
Inspector.new(id: 1, name: "name").inspect
|
49
|
+
).to match(
|
50
|
+
/(?x-mi:\#<Inspector:0x[0-9a-f]+>\ {\n\ \ \ \ \ \ :id\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[1;34m1\x1B\[0m,\n\ \ \ \ :name\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[0;33m"name"\x1B\[0m\n})/
|
51
|
+
)
|
16
52
|
end
|
17
53
|
|
18
|
-
|
19
|
-
|
20
|
-
|
54
|
+
it "formats a collection" do
|
55
|
+
expect(Inspectors.new.all.inspect).to match(/Inspectors\s+{.*}$/m) # close enough
|
56
|
+
end
|
57
|
+
end
|
21
58
|
|
22
|
-
|
23
|
-
|
59
|
+
describe Cistern::Formatter::Formatador do
|
60
|
+
before { Cistern.formatter = described_class }
|
24
61
|
|
25
|
-
|
26
|
-
|
62
|
+
it "formats a model" do
|
63
|
+
Cistern.formatter = Cistern::Formatter::Formatador
|
27
64
|
|
28
|
-
|
65
|
+
expect(Inspector.new(id: 1, name: "name").inspect).to eq(%q{ <Inspector
|
29
66
|
id=1,
|
30
67
|
name="name"
|
31
68
|
>})
|
32
|
-
end
|
33
69
|
end
|
34
70
|
|
35
|
-
|
36
|
-
|
37
|
-
Cistern.formatter = Cistern::Formatter::Formatador
|
38
|
-
expect(Inspectors.new.all.inspect).to eq(%q{ <Inspectors
|
71
|
+
it "formats a collection" do
|
72
|
+
expect(Inspectors.new.all.inspect).to eq(%q{ <Inspectors
|
39
73
|
[
|
40
74
|
<Inspector
|
41
75
|
id=1,
|
@@ -47,11 +81,5 @@ describe "#inspect" do
|
|
47
81
|
>
|
48
82
|
]
|
49
83
|
>})
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should use awesome_print" do
|
53
|
-
Cistern.formatter = Cistern::Formatter::AwesomePrint
|
54
|
-
expect(Inspectors.new.all.inspect).to match(/Inspectors\s+{.*}$/m) # close enough
|
55
|
-
end
|
56
84
|
end
|
57
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cistern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: API client framework extracted from Fog
|
14
14
|
email:
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/cistern/data/redis.rb
|
37
37
|
- lib/cistern/formatter.rb
|
38
38
|
- lib/cistern/formatter/awesome_print.rb
|
39
|
+
- lib/cistern/formatter/default.rb
|
39
40
|
- lib/cistern/formatter/formatador.rb
|
40
41
|
- lib/cistern/hash.rb
|
41
42
|
- lib/cistern/mock.rb
|
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
82
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.4.5
|
83
84
|
signing_key:
|
84
85
|
specification_version: 4
|
85
86
|
summary: API client framework
|
@@ -96,4 +97,3 @@ test_files:
|
|
96
97
|
- spec/spec_helper.rb
|
97
98
|
- spec/support/service.rb
|
98
99
|
- spec/wait_for_spec.rb
|
99
|
-
has_rdoc:
|