cistern 0.11.2.pre2 → 0.11.2

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: 1fd7d5118bf1337d421cb49d37ec448c99a6a348
4
- data.tar.gz: 3eb9da77dd49b2fdca439c4d0112af1ecf3e0d36
3
+ metadata.gz: 3ae50687387de9d226da400b9d56bf97f2ecddc4
4
+ data.tar.gz: 93febb3647951b17b4aa0f076e4610d022db788b
5
5
  SHA512:
6
- metadata.gz: 26f8cf18cabc2699cd6b8e1ab18628408254e9ad3dc3d992cf923b322c3fae6bfc5b1406decb255ba969031fd98ea03d7eb39780915d4cd97048d46e9bcbead3
7
- data.tar.gz: 36f14d5bfbfae722156cd722ddae8fe4b5f4028631d98578f56ab2cef8812153d74fc8130cc98c95ee885b831c371554fdbc5da1c865c2f7ad7684fad78d1aa5
6
+ metadata.gz: 30e2383f0df43ffd95fdee028407993d6eccfba52c27ddece42d5244a7ae5f5608c8106417f519b8bcbf47bb11a5a4fe2ac76acd8e88acf0a01006bdc9171ced
7
+ data.tar.gz: 00ee7d048ebfc6cec54eea637d8c2da9eb3ce7cfba85513492097058046210de942359c439541fe9e99e6c1ab762827e9d4669f5e5e6a0783282649f71cdff20
data/.gemrelease ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ bump:
3
+ tag: true
data/README.md CHANGED
@@ -208,7 +208,7 @@ Patient::Mock.store_in(:hash)
208
208
 
209
209
  ### Model
210
210
 
211
- * `service` represents the associated `Foo::Client` instance.
211
+ * `connection` represents the associated `Foo::Client` instance.
212
212
  * `collection` represents the related collection (if applicable)
213
213
 
214
214
  Example
@@ -225,7 +225,7 @@ class Foo::Client::Bar < Cistern::Model
225
225
  params = {
226
226
  "id" => self.identity
227
227
  }
228
- self.service.destroy_bar(params).body["request"]
228
+ self.connection.destroy_bar(params).body["request"]
229
229
  end
230
230
 
231
231
  def save
@@ -239,11 +239,11 @@ class Foo::Client::Bar < Cistern::Model
239
239
  }
240
240
 
241
241
  if new_record?
242
- merge_attributes(service.create_bar(params).body["bar"])
242
+ merge_attributes(connection.create_bar(params).body["bar"])
243
243
  else
244
244
  requires :identity
245
245
 
246
- merge_attributes(service.update_bar(params).body["bar"])
246
+ merge_attributes(connection.update_bar(params).body["bar"])
247
247
  end
248
248
  end
249
249
  end
@@ -286,7 +286,7 @@ class Foo::Client::Bars < Cistern::Collection
286
286
  model Foo::Client::Bar
287
287
 
288
288
  def all(params = {})
289
- response = service.get_bars(params)
289
+ response = connection.get_bars(params)
290
290
 
291
291
  data = response.body
292
292
 
@@ -300,11 +300,11 @@ class Foo::Client::Bars < Cistern::Collection
300
300
  }
301
301
  params.merge!("location" => options[:location]) if options.key?(:location)
302
302
 
303
- service.requests.new(service.discover_bar(params).body["request"])
303
+ connection.requests.new(connection.discover_bar(params).body["request"])
304
304
  end
305
305
 
306
306
  def get(id)
307
- if data = service.get_bar("id" => id).body["bar"]
307
+ if data = connection.get_bar("id" => id).body["bar"]
308
308
  new(data)
309
309
  else
310
310
  nil
@@ -173,26 +173,39 @@ module Cistern::Attributes
173
173
  end
174
174
 
175
175
  def merge_attributes(new_attributes = {})
176
+ protected_methods = (Cistern::Model.instance_methods - [:connection, :identity, :collection])
177
+ ignored_attributes = self.class.ignored_attributes
178
+ class_attributes = self.class.attributes
179
+ class_aliases = self.class.aliases
180
+
176
181
  new_attributes.each do |_key, value|
177
- key = _key.to_s.to_sym
182
+ string_key = _key.kind_of?(String) ? _key : _key.to_s
183
+ symbol_key = case _key
184
+ when String
185
+ _key.to_sym
186
+ when Symbol
187
+ _key
188
+ else
189
+ string_key.to_sym
190
+ end
191
+
178
192
  # find nested paths
179
- value.is_a?(::Hash) && self.class.attributes.each do |name, options|
180
- if (options[:squash] || []).first == key.to_s
181
- send("#{name}=", {key => value})
193
+ value.is_a?(::Hash) && class_attributes.each do |name, options|
194
+ if options[:squash] && options[:squash].first == string_key
195
+ send("#{name}=", {symbol_key => value})
182
196
  end
183
197
  end
184
198
 
185
- unless self.class.ignored_attributes.include?(key)
186
- if self.class.aliases.has_key?(key)
187
- self.class.aliases[key].each do |aliased_key|
199
+ unless ignored_attributes.include?(symbol_key)
200
+ if class_aliases.has_key?(symbol_key)
201
+ class_aliases[symbol_key].each do |aliased_key|
188
202
  send("#{aliased_key}=", value)
189
203
  end
190
204
  end
191
205
 
192
- protected_methods = Cistern::Model.instance_methods - [:service, :identity, :collection]
193
-
194
- if !protected_methods.include?(key) && self.respond_to?("#{key}=", true)
195
- send("#{key}=", value)
206
+ assignment_method = "#{string_key}="
207
+ if !protected_methods.include?(symbol_key) && self.respond_to?(assignment_method, true)
208
+ send(assignment_method, value)
196
209
  end
197
210
  end
198
211
  end
@@ -236,7 +249,7 @@ module Cistern::Attributes
236
249
  protected
237
250
 
238
251
  def missing_attributes(args)
239
- ([:service] | args).select{|arg| send("#{arg}").nil?}
252
+ ([:connection] | args).select{|arg| send("#{arg}").nil?}
240
253
  end
241
254
 
242
255
  def changed!(attribute, from, to)
@@ -1,4 +1,6 @@
1
- module Cistern::Collection
1
+ class Cistern::Collection
2
+ extend Cistern::Attributes::ClassMethods
3
+ include Cistern::Attributes::InstanceMethods
2
4
 
3
5
  BLACKLISTED_ARRAY_METHODS = [
4
6
  :compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!,
@@ -6,21 +8,13 @@ module Cistern::Collection
6
8
  :keep_if, :pop, :shift, :delete_at, :compact
7
9
  ].to_set # :nodoc:
8
10
 
9
- def self.service_collection(service, klass)
10
- plural_name = Cistern::String.underscore(Cistern::String.demodulize(klass.name))
11
+ attr_accessor :records, :loaded, :connection
11
12
 
12
- service.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
13
- def #{plural_name}(attributes={})
14
- #{klass.name}.new(attributes.merge(service: self))
15
- end
16
- EOS
17
- end
18
-
19
- attr_accessor :records, :loaded, :service
20
-
21
- module ClassMethods
22
- def model(new_model=nil)
23
- @model ||= new_model
13
+ def self.model(new_model=nil)
14
+ if new_model == nil
15
+ @model
16
+ else
17
+ @model = new_model
24
18
  end
25
19
  end
26
20
 
@@ -79,7 +73,7 @@ module Cistern::Collection
79
73
  model.new(
80
74
  {
81
75
  :collection => self,
82
- :service => service,
76
+ :connection => connection,
83
77
  }.merge(attributes)
84
78
  )
85
79
  end
data/lib/cistern/model.rb CHANGED
@@ -1,12 +1,8 @@
1
- module Cistern::Model
1
+ class Cistern::Model
2
+ extend Cistern::Attributes::ClassMethods
2
3
  include Cistern::Attributes::InstanceMethods
3
4
 
4
- def self.included(klass)
5
- klass.send(:extend, Cistern::Attributes::ClassMethods)
6
- klass.send(:include, Cistern::Attributes::InstanceMethods)
7
- end
8
-
9
- attr_accessor :collection, :service
5
+ attr_accessor :collection, :connection
10
6
 
11
7
  def inspect
12
8
  if Cistern.formatter
@@ -56,15 +52,15 @@ module Cistern::Model
56
52
  end
57
53
  end
58
54
 
59
- def wait_for(timeout = self.service_class.timeout, interval = self.service_class.poll_interval, &block)
60
- service_class.wait_for(timeout, interval) { reload && block.call(self) }
55
+ def service
56
+ self.connection ? self.connection.class : Cistern
61
57
  end
62
58
 
63
- def wait_for!(timeout = self.service_class.timeout, interval = self.service_class.poll_interval, &block)
64
- service_class.wait_for!(timeout, interval) { reload && block.call(self) }
59
+ def wait_for(timeout = self.service.timeout, interval = self.service.poll_interval, &block)
60
+ service.wait_for(timeout, interval) { reload && block.call(self) }
65
61
  end
66
62
 
67
- def service_class
68
- self.service ? self.service.class : Cistern
63
+ def wait_for!(timeout = self.service.timeout, interval = self.service.poll_interval, &block)
64
+ service.wait_for!(timeout, interval) { reload && block.call(self) }
69
65
  end
70
66
  end
@@ -42,44 +42,6 @@ class Cistern::Service
42
42
  def initialize(options={})
43
43
  end
44
44
  end
45
-
46
- class Model
47
- include Cistern::Model
48
-
49
- def self.service
50
- #{klass.name}
51
- end
52
- end
53
-
54
- class Collection
55
- include Cistern::Collection
56
-
57
- def self.inherited(klass)
58
- klass.extend(Cistern::Attributes::ClassMethods)
59
- klass.extend(Cistern::Collection::ClassMethods)
60
- klass.include(Cistern::Attributes::InstanceMethods)
61
-
62
- Cistern::Collection.service_collection(service, klass)
63
- end
64
-
65
- def self.service
66
- #{klass.name}
67
- end
68
- end
69
-
70
- class Request
71
- include Cistern::Request
72
-
73
- def self.inherited(klass)
74
- klass.extend(Cistern::Request::ClassMethods)
75
-
76
- Cistern::Request.service_request(service, klass)
77
- end
78
-
79
- def self.service
80
- #{klass.name}
81
- end
82
- end
83
45
  EOS
84
46
 
85
47
  klass.send(:const_set, :Timeout, Class.new(Cistern::Error))
@@ -95,6 +57,30 @@ class Cistern::Service
95
57
  klass::Real.timeout_error = klass::Timeout
96
58
  end
97
59
 
60
+ def collection_path(collection_path = nil)
61
+ if collection_path
62
+ @collection_path = collection_path
63
+ else
64
+ @collection_path
65
+ end
66
+ end
67
+
68
+ def model_path(model_path = nil)
69
+ if model_path
70
+ @model_path = model_path
71
+ else
72
+ @model_path
73
+ end
74
+ end
75
+
76
+ def request_path(request_path = nil)
77
+ if request_path
78
+ @request_path = request_path
79
+ else
80
+ @request_path
81
+ end
82
+ end
83
+
98
84
  def collections
99
85
  @collections ||= []
100
86
  end
@@ -123,10 +109,22 @@ class Cistern::Service
123
109
  self.recognized_arguments.concat(args)
124
110
  end
125
111
 
112
+ def model(model_name, options={})
113
+ models << [model_name, options]
114
+ end
115
+
126
116
  def mocked_requests
127
117
  @mocked_requests ||= []
128
118
  end
129
119
 
120
+ def request(request_name, options={})
121
+ requests << [request_name, options]
122
+ end
123
+
124
+ def collection(collection_name, options={})
125
+ collections << [collection_name, options]
126
+ end
127
+
130
128
  def validate_options(options={})
131
129
  required_options = Cistern::Hash.slice(options, *required_arguments)
132
130
 
@@ -143,8 +141,66 @@ class Cistern::Service
143
141
  end
144
142
  end
145
143
 
144
+ def setup_requirements
145
+ @required ||= false
146
+ unless @required
147
+
148
+ # setup models
149
+ models.each do |model, options|
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
+
157
+ self.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
158
+ def #{singular_name}(attributes={})
159
+ #{service}::#{class_name}.new({connection: self}.merge(attributes))
160
+ end
161
+ EOS
162
+ end
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))
168
+ end
169
+
170
+ if service::Mock.method_defined?(request)
171
+ mocked_requests << request
172
+ else
173
+ service::Mock.module_eval <<-EOS, __FILE__, __LINE__
174
+ def #{request}(*args)
175
+ Cistern::Mock.not_implemented(request)
176
+ end
177
+ EOS
178
+ end
179
+ end
180
+
181
+ # setup collections
182
+ collections.each do |collection, options|
183
+ unless options[:require] == false
184
+ require(options[:require] || File.join(@collection_path || @model_path, collection.to_s))
185
+ end
186
+
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
+
190
+ self.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
191
+ def #{plural_name}(attributes={})
192
+ #{service}::#{class_name}.new({connection: self}.merge(attributes))
193
+ end
194
+ EOS
195
+ end
196
+
197
+ @required = true
198
+ end
199
+ end
200
+
146
201
  def new(options={})
147
202
  validate_options(options)
203
+ setup_requirements
148
204
 
149
205
  self.const_get(self.mocking? ? :Mock : :Real).new(options)
150
206
  end
@@ -2,7 +2,7 @@ class Cistern::Singular
2
2
  extend Cistern::Attributes::ClassMethods
3
3
  include Cistern::Attributes::InstanceMethods
4
4
 
5
- attr_accessor :service
5
+ attr_accessor :connection
6
6
 
7
7
  def inspect
8
8
  if Cistern.formatter
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "0.11.2.pre2"
2
+ VERSION = "0.11.2"
3
3
  end
data/lib/cistern.rb CHANGED
@@ -9,7 +9,6 @@ module Cistern
9
9
  Timeout = Class.new(Error)
10
10
 
11
11
  require 'cistern/hash'
12
- require 'cistern/string'
13
12
  require 'cistern/mock'
14
13
  require 'cistern/wait_for'
15
14
  require 'cistern/attributes'
@@ -17,7 +16,6 @@ module Cistern
17
16
  require 'cistern/model'
18
17
  require 'cistern/service'
19
18
  require 'cistern/singular'
20
- require 'cistern/request'
21
19
  require 'cistern/data'
22
20
  require 'cistern/data/hash'
23
21
  require 'cistern/data/redis'
@@ -1,12 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Cistern::Collection" do
4
- class SampleCollectionModel < Sample::Model
4
+
5
+ class SampleCollectionModel < Cistern::Model
5
6
  identity :id
6
7
  attribute :name
7
8
  end
8
9
 
9
- class SampleCollection < Sample::Collection
10
+ class SampleCollection < Cistern::Collection
10
11
  model SampleCollectionModel
11
12
 
12
13
  def all
data/spec/dirty_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Cistern::Model#dirty" do
4
- class DirtySpec < Sample::Model
4
+ class DirtySpec < Cistern::Model
5
5
  identity :id
6
6
 
7
7
  attribute :name
@@ -1,12 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "#inspect" do
4
- class Inspector < Sample::Model
4
+ class Inspector < Cistern::Model
5
5
  identity :id
6
6
  attribute :name
7
7
  end
8
8
 
9
- class Inspectors < Sample::Collection
9
+ class Inspectors < Cistern::Collection
10
+
10
11
  model Inspector
11
12
 
12
13
  def all(options={})
@@ -1,31 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'mock data' do
4
- class Diagnosis < Sample::Request
5
- def real(diagnosis)
6
- end
4
+ class Patient < Cistern::Service
5
+ request :diagnosis
6
+ request :treat
7
7
 
8
- def mock(diagnosis)
9
- service.data.store(:diagnosis, service.data.fetch(:diagnosis) + [diagnosis])
10
- end
11
- end
8
+ class Real
9
+ def diagnosis(options={})
10
+ end
12
11
 
13
- class Treat < Sample::Request
14
- def real(treatment)
12
+ def treat(options={})
13
+ end
15
14
  end
16
15
 
17
- def mock(treatment)
18
- service.data[:treatments] += [treatment]
16
+ class Mock
17
+ def diagnosis(diagnosis)
18
+ #self.data[:diagnosis] << rand(2) == 0 ? "sick" : "healthy"
19
+ self.data.store(:diagnosis, self.data.fetch(:diagnosis) + [diagnosis])
20
+ end
21
+
22
+ def treat(treatment)
23
+ self.data[:treatments] += [treatment]
24
+ end
19
25
  end
20
26
  end
21
27
 
22
28
  shared_examples "mock_data#backend" do |backend, options|
23
29
  it "should store mock data" do
24
- Sample.mock!
25
- Sample::Mock.store_in(backend, options)
26
- Sample.reset!
30
+ Patient.mock!
31
+ Patient::Mock.store_in(backend, options)
32
+ Patient.reset!
27
33
 
28
- p = Sample.new
34
+ p = Patient.new
29
35
  p.diagnosis("sick")
30
36
  expect(p.data[:diagnosis]).to eq(["sick"])
31
37
 
@@ -36,7 +42,7 @@ describe 'mock data' do
36
42
  p.treat("healthy")
37
43
  expect(p.data[:treatments]).to eq(["healthy"])
38
44
 
39
- Sample.reset!
45
+ Patient.reset!
40
46
 
41
47
  expect(p.data[:treatments]).to eq([])
42
48
  end
data/spec/model_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "Cistern::Model" do
4
4
  describe "#update" do
5
- class UpdateSpec < Sample::Model
5
+ class UpdateSpec < Cistern::Model
6
6
  identity :id
7
7
  attribute :name
8
8
  attribute :properties
@@ -21,7 +21,7 @@ describe "Cistern::Model" do
21
21
  end
22
22
 
23
23
  it "should duplicate a model" do
24
- class DupSpec < Sample::Model
24
+ class DupSpec < Cistern::Model
25
25
  identity :id
26
26
  attribute :name
27
27
  attribute :properties
@@ -38,7 +38,7 @@ describe "Cistern::Model" do
38
38
  end
39
39
 
40
40
  context "attribute parsing" do
41
- class TypeSpec < Sample::Model
41
+ class TypeSpec < Cistern::Model
42
42
  identity :id
43
43
  attribute :name, type: :string
44
44
  attribute :created_at, type: :time
@@ -155,17 +155,17 @@ describe "Cistern::Model" do
155
155
 
156
156
  describe "#requires" do
157
157
  it "should raise if attribute not provided" do
158
- expect { TypeSpec.new({"service" => "fake", "something" => {"id" => "12"}}).save }.to raise_exception(ArgumentError)
158
+ expect { TypeSpec.new({"connection" => "fake", "something" => {"id" => "12"}}).save }.to raise_exception(ArgumentError)
159
159
  end
160
160
 
161
161
  it "should raise if attribute is provided and is nil" do
162
- expect { TypeSpec.new({"service" => "fake", "custom" => nil}).save }.to raise_exception(ArgumentError)
162
+ expect { TypeSpec.new({"connection" => "fake", "custom" => nil}).save }.to raise_exception(ArgumentError)
163
163
  end
164
164
  end
165
165
  end
166
166
 
167
167
  context "attribute coverage info collecting", :coverage do
168
- class CoverageSpec < Sample::Model
168
+ class CoverageSpec < Cistern::Model
169
169
  identity :id
170
170
 
171
171
  attribute :used, type: :string
@@ -6,8 +6,8 @@ describe "Cistern::Singular" do
6
6
  attribute :count, type: :number
7
7
 
8
8
  def fetch_attributes
9
- #test that initialize waits for service to be defined
10
- raise "missing service" unless service
9
+ #test that initialize waits for connection to be defined
10
+ raise "missing connection" unless connection
11
11
 
12
12
  @counter ||= 0
13
13
  @counter += 1
@@ -16,11 +16,11 @@ describe "Cistern::Singular" do
16
16
  end
17
17
 
18
18
  it "should work" do
19
- expect(SampleSingular.new(service: :fake).name).to eq("amazing")
19
+ expect(SampleSingular.new(connection: :fake).name).to eq("amazing")
20
20
  end
21
21
 
22
22
  it "should reload" do
23
- singular = SampleSingular.new(service: :fake)
23
+ singular = SampleSingular.new(connection: :fake)
24
24
  old_count = singular.count
25
25
  expect(singular.count).to eq(old_count)
26
26
  expect(singular.reload.count).to be > old_count
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,6 @@ if ENV["TRAVIS"]
4
4
  end
5
5
 
6
6
  require File.expand_path('../../lib/cistern', __FILE__)
7
- Dir[File.expand_path("../{support,shared,matchers,fixtures}/*.rb", __FILE__)].each{|f| require(f)}
8
7
 
9
8
  Bundler.require(:test)
10
9
 
@@ -1,13 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
- class WaitForModel < Sample::Model
3
+ class WaitForService < Cistern::Service
4
+ model :wait_for_model, require: false
5
+ collection :wait_for_models, require: false
6
+
7
+ class Real
8
+ def initialize(*args)
9
+ end
10
+ end
11
+ end
12
+
13
+ class WaitForService::WaitForModel < Cistern::Model
4
14
  identity :id
5
15
 
6
16
  attribute :name
7
17
  end
8
18
 
9
- class WaitForModels < Sample::Collection
10
- model WaitForModel
19
+ class WaitForService::WaitForModels < Cistern::Collection
20
+ model WaitForService::WaitForModel
11
21
 
12
22
  def get(identity)
13
23
  self
@@ -27,17 +37,17 @@ describe 'Cistern#wait_for!' do
27
37
  end
28
38
 
29
39
  describe 'Cistern::Model#wait_for!' do
30
- let(:service) { Sample.new }
40
+ let(:service) { WaitForService.new }
31
41
  let(:model) { service.wait_for_models.new(identity: 1) }
32
42
 
33
43
  it "should raise if timeout exceeded" do
34
- expect { model.wait_for!(0, 0) { false } }.to raise_exception(Sample::Timeout)
44
+ expect { model.wait_for!(0, 0) { false } }.to raise_exception(WaitForService::Timeout)
35
45
  end
36
46
  end
37
47
 
38
48
 
39
49
  describe "WaitForModel#timeout" do
40
- let(:service) { Sample.new }
50
+ let(:service) { WaitForService.new }
41
51
  let(:model) { service.wait_for_models.new(identity: 1) }
42
52
 
43
53
  it "should use service-specific timeout in #wait_for" do
@@ -49,7 +59,7 @@ describe "WaitForModel#timeout" do
49
59
  timeout(2) do
50
60
  expect do
51
61
  model.wait_for! { sleep(0.2); elapsed += 0.2; elapsed > 0.2 }
52
- end.to raise_exception(Sample::Timeout)
62
+ end.to raise_exception(WaitForService::Timeout)
53
63
  end
54
64
  end
55
65
 
@@ -62,7 +72,7 @@ describe "WaitForModel#timeout" do
62
72
  timeout(2) do
63
73
  expect do
64
74
  model.wait_for!(0.1) { sleep(0.2); elapsed += 0.2; elapsed > 0.2 }
65
- end.to raise_exception(Sample::Timeout)
75
+ end.to raise_exception(WaitForService::Timeout)
66
76
  end
67
77
  end
68
78
  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: 0.11.2.pre2
4
+ version: 0.11.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-10-21 00:00:00.000000000 Z
11
+ date: 2014-11-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: API client framework extracted from Fog
14
14
  email:
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".gemrelease"
20
21
  - ".gitignore"
21
22
  - ".travis.yml"
22
23
  - Gemfile
@@ -39,10 +40,8 @@ files:
39
40
  - lib/cistern/hash.rb
40
41
  - lib/cistern/mock.rb
41
42
  - lib/cistern/model.rb
42
- - lib/cistern/request.rb
43
43
  - lib/cistern/service.rb
44
44
  - lib/cistern/singular.rb
45
- - lib/cistern/string.rb
46
45
  - lib/cistern/timeout.rb
47
46
  - lib/cistern/version.rb
48
47
  - lib/cistern/wait_for.rb
@@ -52,11 +51,8 @@ files:
52
51
  - spec/hash_spec.rb
53
52
  - spec/mock_data_spec.rb
54
53
  - spec/model_spec.rb
55
- - spec/request_spec.rb
56
- - spec/service_spec.rb
57
54
  - spec/singular_spec.rb
58
55
  - spec/spec_helper.rb
59
- - spec/support/service.rb
60
56
  - spec/wait_for_spec.rb
61
57
  homepage: http://joshualane.com/cistern
62
58
  licenses:
@@ -73,9 +69,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
69
  version: '0'
74
70
  required_rubygems_version: !ruby/object:Gem::Requirement
75
71
  requirements:
76
- - - ">"
72
+ - - ">="
77
73
  - !ruby/object:Gem::Version
78
- version: 1.3.1
74
+ version: '0'
79
75
  requirements: []
80
76
  rubyforge_project:
81
77
  rubygems_version: 2.2.2
@@ -89,10 +85,7 @@ test_files:
89
85
  - spec/hash_spec.rb
90
86
  - spec/mock_data_spec.rb
91
87
  - spec/model_spec.rb
92
- - spec/request_spec.rb
93
- - spec/service_spec.rb
94
88
  - spec/singular_spec.rb
95
89
  - spec/spec_helper.rb
96
- - spec/support/service.rb
97
90
  - spec/wait_for_spec.rb
98
91
  has_rdoc:
@@ -1,28 +0,0 @@
1
- module Cistern::Request
2
- def self.service_request(service, klass)
3
- request = klass.request_name || Cistern::String.camelize(klass.name)
4
-
5
- service::Mock.module_eval <<-EOS, __FILE__, __LINE__
6
- def #{request}(*args)
7
- #{klass}.new(self).mock(*args)
8
- end
9
- EOS
10
-
11
- service::Real.module_eval <<-EOS, __FILE__, __LINE__
12
- def #{request}(*args)
13
- #{klass}.new(self).real(*args)
14
- end
15
- EOS
16
- end
17
-
18
- attr_reader :service
19
-
20
- def initialize(service)
21
- @service = service
22
- end
23
-
24
- module ClassMethods
25
- def request_name
26
- end
27
- end
28
- end
@@ -1,31 +0,0 @@
1
- class Cistern::String
2
- def self.camelize(string)
3
- string.gsub(/[A-Z]+/) { |w| "_#{w.downcase}" }.gsub(/^_/, "")
4
- end
5
-
6
- # File activesupport/lib/active_support/inflector/methods.rb, line 90
7
- def self.underscore(camel_cased_word)
8
- word = camel_cased_word.to_s.gsub('::', '/')
9
- #word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
10
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
11
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
12
- word.tr!("-", "_")
13
- word.downcase!
14
- word
15
- end
16
-
17
- # File activesupport/lib/active_support/inflector/methods.rb, line 168
18
- def self.demodulize(path)
19
- path = path.to_s
20
- if i = path.rindex('::')
21
- path[(i+2)..-1]
22
- else
23
- path
24
- end
25
- end
26
-
27
- # @todo omg so bad
28
- def self.pluralize(string)
29
- "#{string}s"
30
- end
31
- end
data/spec/request_spec.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Cistern::Request" do
4
- class SampleService < Cistern::Service
5
- recognizes :key
6
-
7
- class Real
8
- attr_reader :service_args
9
-
10
- def initialize(*args)
11
- @service_args = args
12
- end
13
- end
14
- end
15
-
16
- # @todo Sample::Service.request
17
- class ListSamples < SampleService::Request
18
- # @todo name
19
- # name :list_all_samples
20
- def real(*args)
21
- service.service_args + args + ["real"]
22
- end
23
-
24
- def mock(*args)
25
- args + ["mock"]
26
- end
27
- end
28
-
29
- it "should execute a new-style request" do
30
- expect(SampleService.new.list_samples("sample1")).to eq([{}, "sample1", "real"])
31
- expect(SampleService::Real.new.list_samples("sample2")).to eq(["sample2", "real"])
32
- expect(SampleService::Mock.new.list_samples("sample3")).to eq(["sample3", "mock"])
33
-
34
- # service access
35
- expect(SampleService.new(:key => "value").list_samples("stat")).to eq([{:key => "value"}, "stat", "real"])
36
- end
37
- end
data/spec/service_spec.rb DELETED
File without changes
@@ -1 +0,0 @@
1
- class Sample < Cistern::Service; end