cistern 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 486d6ae38fe4fb055f282a50835760d082fbebd9
4
- data.tar.gz: aa7beb5d10b38bfcfa328ea86d5c7aaff78c080b
3
+ metadata.gz: 62a24a469ced62056ea61f768a991144ea7dad32
4
+ data.tar.gz: 30ca44a90ed296c9018078bf7e7ea4ee47e0925f
5
5
  SHA512:
6
- metadata.gz: f3f29767bf7851718531c0611a6b32b2fca7e0d841f40e13088fe5531a9cf70473049c9da3e3bf782b751b1a6b2717e376d8ad960c807c7794cf98190dc84b1a
7
- data.tar.gz: 00b3db9eb18a8e047230bd776bb539630055a7811184d0bd77479ddd4a26680a4580dd6f06e7ae09a5b5a2c639d67aa1916673bd7ac4a4df875ca04886bb9140
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 'foo' then a good name is 'Foo::Client'.
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`. `recognizes` parameters are optional.
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 specific the name of generated method.
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
@@ -7,6 +7,10 @@ module Cistern::Formatter
7
7
  Cistern::Formatter::AwesomePrint
8
8
  elsif defined?(::Formatador)
9
9
  Cistern::Formatter::Formatador
10
+ else
11
+ Cistern::Formatter::Default
10
12
  end
11
13
  end
12
14
  end
15
+
16
+ require 'cistern/formatter/default'
@@ -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
@@ -24,11 +24,7 @@ module Cistern::Model
24
24
  attr_accessor :collection, :service
25
25
 
26
26
  def inspect
27
- if Cistern.formatter
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={})
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
@@ -1,41 +1,75 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#inspect" do
4
- class Inspector < Sample::Model
5
- identity :id
6
- attribute :name
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
- class Inspectors < Sample::Collection
10
- model Inspector
43
+ describe Cistern::Formatter::AwesomePrint do
44
+ before { Cistern.formatter = described_class }
11
45
 
12
- def all(options={})
13
- merge_attributes(options)
14
- self.load([{id: 1, name: "2"},{id: 3, name: "4"}])
15
- end
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
- describe "Cistern::Model" do
19
- it "should use awesome_print" do
20
- Cistern.formatter = Cistern::Formatter::AwesomePrint
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
- Inspector.new(id: 1, name: "name").inspect.match /(?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})/
23
- end
59
+ describe Cistern::Formatter::Formatador do
60
+ before { Cistern.formatter = described_class }
24
61
 
25
- it "should use formatador" do
26
- Cistern.formatter = Cistern::Formatter::Formatador
62
+ it "formats a model" do
63
+ Cistern.formatter = Cistern::Formatter::Formatador
27
64
 
28
- expect(Inspector.new(id: 1, name: "name").inspect).to eq(%q{ <Inspector
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
- describe "Cistern::Collection" do
36
- it "should use formatador" do
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.2
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-03-31 00:00:00.000000000 Z
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.2.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: