cistern 2.2.1 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32675f1c34663bf47fbea19c1f56e009884b8851
4
- data.tar.gz: bd418e9510d7dfde5bc563a0e8a3471b174c6a2a
3
+ metadata.gz: 271e3b4819b0195e672410246c8388ff65f88ad0
4
+ data.tar.gz: 8be7d35f9a52253069c3dc19a6ab969ceeeb0b7f
5
5
  SHA512:
6
- metadata.gz: 4f5044d67c9c3195a7ea0ec3f50186c4746aba1dec07cb16e582dc92d5b35219e913b9eeaef651ea75f71e6fc143603216339179627a516975741ccbf0c26014
7
- data.tar.gz: 9db86cbe754c36b2c3f07e33b1b44c01d1c10dc97a746a61dd59cc1f616dd7574477b09c3ef0af24a5d1c7c025ff8a6d7162591c81ab4679746b2a1223bef0c7
6
+ metadata.gz: d863ffdb75969540acb17e44746d4432bde8ee733ccacc48da7ec3fbe47a099a77f191f1057c216a7a1471beebb1158952102ef304136094bee9d3c14e787500
7
+ data.tar.gz: 7834397862a3ec7262f979dd26bc6253fa345a98188e99df373b8633c9c4cdf00a55f0744130a6d8f5e35422b715dccfae4bc5837292b2e91aba3a457e4021ec
@@ -38,6 +38,7 @@ module Cistern::Client
38
38
  request_class = options[:request] || "Request"
39
39
  collection_class = options[:collection] || "Collection"
40
40
  model_class = options[:model] || "Model"
41
+ singular_class = options[:singular] || "Singular"
41
42
 
42
43
  interface = options[:interface] || :class
43
44
  interface_callback = (:class == interface) ? :inherited : :included
@@ -83,6 +84,20 @@ module Cistern::Client
83
84
  end
84
85
  end
85
86
 
87
+ #{interface} #{singular_class}
88
+ def self.#{interface_callback}(klass)
89
+ service.singularities << klass
90
+
91
+ klass.send(:include, ::Cistern::Singular)
92
+
93
+ super
94
+ end
95
+
96
+ def self.service
97
+ #{klass.name}
98
+ end
99
+ end
100
+
86
101
  #{interface} #{collection_class}
87
102
  include ::Cistern::Collection
88
103
 
@@ -154,6 +169,10 @@ module Cistern::Client
154
169
  @_models ||= []
155
170
  end
156
171
 
172
+ def singularities
173
+ @_singularities ||= []
174
+ end
175
+
157
176
  def recognized_arguments
158
177
  @_recognized_arguments ||= []
159
178
  end
@@ -214,6 +233,13 @@ module Cistern::Client
214
233
  Cistern::Model.service_model(self, klass, name)
215
234
  end
216
235
 
236
+ singularities.each do |klass|
237
+ name = klass.service_method ||
238
+ Cistern::String.underscore(klass.name.gsub("#{self.name}::", "").gsub("::", ""))
239
+
240
+ Cistern::Singular.service_singular(self, klass, name)
241
+ end
242
+
217
243
  @_setup = true
218
244
  end
219
245
 
@@ -1,15 +1,23 @@
1
- class Cistern::Singular
2
- extend Cistern::Attributes::ClassMethods
3
- include Cistern::Attributes::InstanceMethods
1
+ module Cistern::Singular
2
+
3
+ def self.service_singular(service, klass, name)
4
+ service.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
5
+ def #{name}(attributes={})
6
+ #{klass.name}.new(attributes.merge(service: self))
7
+ end
8
+ EOS
9
+ end
10
+
11
+ def self.included(klass)
12
+ klass.send(:extend, Cistern::Attributes::ClassMethods)
13
+ klass.send(:include, Cistern::Attributes::InstanceMethods)
14
+ klass.send(:extend, Cistern::Model::ClassMethods)
15
+ end
4
16
 
5
17
  attr_accessor :service
6
18
 
7
19
  def inspect
8
- if Cistern.formatter
9
- Cistern.formatter.call(self)
10
- else
11
- "#<#{self.class}>"
12
- end
20
+ Cistern.formatter.call(self)
13
21
  end
14
22
 
15
23
  def initialize(options)
@@ -18,7 +26,9 @@ class Cistern::Singular
18
26
  end
19
27
 
20
28
  def reload
21
- if new_attributes = fetch_attributes
29
+ new_attributes = fetch_attributes
30
+
31
+ if new_attributes
22
32
  merge_attributes(new_attributes)
23
33
  end
24
34
  end
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.3"
3
3
  end
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Cistern::Singular" do
4
- class SampleSingular < Cistern::Singular
4
+ class SampleSingular < Sample::Singular
5
+
5
6
  attribute :name
6
7
  attribute :count, type: :number
7
8
 
@@ -16,11 +17,11 @@ describe "Cistern::Singular" do
16
17
  end
17
18
 
18
19
  it "should work" do
19
- expect(SampleSingular.new(service: :fake).name).to eq("amazing")
20
+ expect(Sample.new.sample_singular.name).to eq("amazing")
20
21
  end
21
22
 
22
23
  it "should reload" do
23
- singular = SampleSingular.new(service: :fake)
24
+ singular = Sample.new.sample_singular
24
25
  old_count = singular.count
25
26
  expect(singular.count).to eq(old_count)
26
27
  expect(singular.reload.count).to be > old_count
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.2.1
4
+ version: 2.2.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-10-02 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: API client framework extracted from Fog
14
14
  email: