cistern 0.9.2 → 0.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e2a073ec9812c931fb912227d9ad1c2b90e2f3e
4
- data.tar.gz: aedb93e04e22e42d386c9608f3b18bdc18d3987e
3
+ metadata.gz: 654c51d23fb889c16d378ffd6b0517dd8a9bea01
4
+ data.tar.gz: bb865084d2e05d0f07647ca6cfc193aae4ba277a
5
5
  SHA512:
6
- metadata.gz: 1ff0f6baa544d2bad3f19eb81b2bc7aa45dc65c8ceecbf3c7b13858143fdc4d3f7c97c8c768af925731a3529ae350eb75891d6169305a35ce7e3b0e1cb2ada14
7
- data.tar.gz: 6d2bf4ed911387a1d2ab0f544092b628a646086e11f3a966d368a9bab8b393fb6dd6f22d0573b09dee81f9f6a50406a2eea3e03adf93b0b94c1aed4dca6d0138
6
+ metadata.gz: 2686e1a240fc0bbca101c446c09a5bd06eed8dd76e15c62243be044afa0316f84d8b5eadefcc8b22b092e3024d155da155a0db176776ab75ca3d4a3391641fa6
7
+ data.tar.gz: 9743c3688790d9b67ba0c24528dced11f0559126eb821103f1eb5d56c13fd1cdb7494b6f0e0d4956fddd3415291f99aac199f1356f733c9d6251494ae08dfe77
@@ -16,6 +16,11 @@ class Cistern::Model
16
16
  merge_attributes(attributes)
17
17
  end
18
18
 
19
+ def update(attributes)
20
+ merge_attributes(attributes)
21
+ save
22
+ end
23
+
19
24
  def save
20
25
  raise NotImplementedError
21
26
  end
@@ -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
- require File.join(@model_path, model.to_s) unless options[:require] == false
149
- class_name = model.to_s.split("_").map(&:capitalize).join
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 #{model}(attributes={})
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
- requests.each do |request|
157
- unless service::Real.method_defined?(request.to_s)
158
- require File.join(@request_path, request.to_s)
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
- if @collection_path
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("_").map(&:capitalize).join
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 #{collection}(attributes={})
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
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "0.9.2"
2
+ VERSION = "0.10.2"
3
3
  end
@@ -1,10 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Cistern::Collection" do
4
+
4
5
  class SampleCollectionModel < Cistern::Model
5
6
  identity :id
6
7
  attribute :name
7
8
  end
9
+
8
10
  class SampleCollection < Cistern::Collection
9
11
  model SampleCollectionModel
10
12
 
@@ -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.9.2
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-08-29 00:00:00.000000000 Z
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: