cistern 0.9.2 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cistern/model.rb +5 -0
- data/lib/cistern/service.rb +25 -15
- data/lib/cistern/version.rb +1 -1
- data/spec/collection_spec.rb +2 -0
- data/spec/model_spec.rb +20 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 654c51d23fb889c16d378ffd6b0517dd8a9bea01
|
4
|
+
data.tar.gz: bb865084d2e05d0f07647ca6cfc193aae4ba277a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2686e1a240fc0bbca101c446c09a5bd06eed8dd76e15c62243be044afa0316f84d8b5eadefcc8b22b092e3024d155da155a0db176776ab75ca3d4a3391641fa6
|
7
|
+
data.tar.gz: 9743c3688790d9b67ba0c24528dced11f0559126eb821103f1eb5d56c13fd1cdb7494b6f0e0d4956fddd3415291f99aac199f1356f733c9d6251494ae08dfe77
|
data/lib/cistern/model.rb
CHANGED
data/lib/cistern/service.rb
CHANGED
@@ -117,8 +117,8 @@ class Cistern::Service
|
|
117
117
|
@mocked_requests ||= []
|
118
118
|
end
|
119
119
|
|
120
|
-
def request(request_name)
|
121
|
-
requests << request_name
|
120
|
+
def request(request_name, options={})
|
121
|
+
requests << [request_name, options]
|
122
122
|
end
|
123
123
|
|
124
124
|
def collection(collection_name, options={})
|
@@ -144,18 +144,27 @@ class Cistern::Service
|
|
144
144
|
def setup_requirements
|
145
145
|
@required ||= false
|
146
146
|
unless @required
|
147
|
+
|
148
|
+
# setup models
|
147
149
|
models.each do |model, options|
|
148
|
-
|
149
|
-
|
150
|
+
unless options[:require] == false
|
151
|
+
require(options[:require] || File.join(@model_path, model.to_s))
|
152
|
+
end
|
153
|
+
|
154
|
+
class_name = options[:class] || model.to_s.split("_").map(&:capitalize).join
|
155
|
+
singular_name = options[:model] || model.to_s.gsub("/", "_")
|
156
|
+
|
150
157
|
self.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
|
151
|
-
def #{
|
158
|
+
def #{singular_name}(attributes={})
|
152
159
|
#{service}::#{class_name}.new({connection: self}.merge(attributes))
|
153
160
|
end
|
154
161
|
EOS
|
155
162
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
163
|
+
|
164
|
+
# setup requests
|
165
|
+
requests.each do |request, options|
|
166
|
+
unless options[:require] == false || service::Real.method_defined?(request.to_s)
|
167
|
+
require(options[:require] || File.join(@request_path, request.to_s))
|
159
168
|
end
|
160
169
|
|
161
170
|
if service::Mock.method_defined?(request)
|
@@ -168,22 +177,23 @@ class Cistern::Service
|
|
168
177
|
EOS
|
169
178
|
end
|
170
179
|
end
|
180
|
+
|
181
|
+
# setup collections
|
171
182
|
collections.each do |collection, options|
|
172
183
|
unless options[:require] == false
|
173
|
-
|
174
|
-
require File.join(@collection_path, collection.to_s)
|
175
|
-
else
|
176
|
-
require File.join(@model_path, collection.to_s)
|
177
|
-
end
|
184
|
+
require(options[:require] || File.join(@collection_path || @model_path, collection.to_s))
|
178
185
|
end
|
179
186
|
|
180
|
-
class_name = collection.to_s.split("
|
187
|
+
class_name = collection.to_s.split("/").map(&:capitalize).join("::").split("_").map { |s| "#{s[0].upcase}#{s[1..-1]}" }.join
|
188
|
+
plural_name = options[:collection] || collection.to_s.gsub("/", "_")
|
189
|
+
|
181
190
|
self.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
|
182
|
-
def #{
|
191
|
+
def #{plural_name}(attributes={})
|
183
192
|
#{service}::#{class_name}.new({connection: self}.merge(attributes))
|
184
193
|
end
|
185
194
|
EOS
|
186
195
|
end
|
196
|
+
|
187
197
|
@required = true
|
188
198
|
end
|
189
199
|
end
|
data/lib/cistern/version.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -2,6 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Cistern::Model" do
|
4
4
|
|
5
|
+
describe "#update" do
|
6
|
+
class UpdateSpec < Cistern::Model
|
7
|
+
identity :id
|
8
|
+
attribute :name
|
9
|
+
attribute :properties
|
10
|
+
|
11
|
+
def save
|
12
|
+
attributes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should merge and save attributes" do
|
17
|
+
model = UpdateSpec.new(name: "steve")
|
18
|
+
model.save
|
19
|
+
|
20
|
+
expect(model.update(name: "karen")).to eq(name: "karen")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
it "should duplicate a model" do
|
6
25
|
class DupSpec < Cistern::Model
|
7
26
|
identity :id
|
@@ -15,7 +34,7 @@ describe "Cistern::Model" do
|
|
15
34
|
expect(duplicate).to eq(model)
|
16
35
|
expect(duplicate).to eql(model)
|
17
36
|
|
18
|
-
model.name= "anotherstring"
|
37
|
+
model.name = "anotherstring"
|
19
38
|
expect(duplicate.name).to eq("string")
|
20
39
|
end
|
21
40
|
|
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: 0.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: API client framework extracted from Fog
|
14
14
|
email:
|