cistern 2.7.0 → 2.7.1

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: be9990e15cdccbe77ea1c27b5a6961fecd445129
4
- data.tar.gz: d466f0e83e49c33fc9dce01eb713b9f1062e8f7e
3
+ metadata.gz: fd667c59a902c0cfb27b3d8f9f07a9fdc79f42cf
4
+ data.tar.gz: f37b9ac705677e8a16e8ca777f5032871ca73d72
5
5
  SHA512:
6
- metadata.gz: dd4a3d7c95873a7fb999854846db84790273ad3366a018dc0e519d7708a13ec325a3a0d1b0bb4968f28cd6260dc4d72659c513513f56dfc2ec0b52ece8a9fb9d
7
- data.tar.gz: 68ca70761102c30cca381a029184250a1750dc01d3c63626afe8b7ecd1929839497a8c6b55f995cef40ad8d5554b534987e1447f44eae567ae6c805cce82c2b5
6
+ metadata.gz: 4e7b9828dac0f8071418073aa20f868f410a493020b816fae0e6e87e1561ad7f899021620a40ff2a12ca362ab1de71231e3db7216571cd52dd142bb993539030
7
+ data.tar.gz: e2452a1049e8b66573ed783db09445a47f0eb6b5cebe4e45651f7cefa0577ae133064b83805d66507c11d8af130c7e6983ee07bf1fc88f4f546134684139d579
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Change Log
2
2
 
3
+ ## [Unreleased](https://github.com/lanej/cistern/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/lanej/cistern/compare/v2.7.0...HEAD)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - custom wait for lambdas [\#21](https://github.com/lanej/cistern/issues/21)
10
+ - accept alias as a attribute parameter [\#20](https://github.com/lanej/cistern/issues/20)
11
+ - Offer mock data adapters [\#19](https://github.com/lanej/cistern/issues/19)
12
+ - request method model [\#4](https://github.com/lanej/cistern/issues/4)
13
+ - Service\#requires\_one [\#3](https://github.com/lanej/cistern/issues/3)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - feature: allow using `super` to override association methods [\#73](https://github.com/lanej/cistern/pull/73) ([lanej](https://github.com/lanej))
18
+ - fix\(associations\): enable attribute options and method scope blocks [\#72](https://github.com/lanej/cistern/pull/72) ([lanej](https://github.com/lanej))
19
+
20
+ ## [v2.7.0](https://github.com/lanej/cistern/tree/v2.7.0) (2016-08-10)
21
+ [Full Changelog](https://github.com/lanej/cistern/compare/v2.6.0...v2.7.0)
22
+
23
+ **Merged pull requests:**
24
+
25
+ - fix\(singular\): add associations support [\#70](https://github.com/lanej/cistern/pull/70) ([lanej](https://github.com/lanej))
26
+ - refactor\(request\): cleanup and document interface [\#69](https://github.com/lanej/cistern/pull/69) ([lanej](https://github.com/lanej))
27
+ - Add a Gitter chat badge to README.md [\#68](https://github.com/lanej/cistern/pull/68) ([gitter-badger](https://github.com/gitter-badger))
28
+
3
29
  ## [v2.6.0](https://github.com/lanej/cistern/tree/v2.6.0) (2016-07-26)
4
30
  [Full Changelog](https://github.com/lanej/cistern/compare/v2.5.0...v2.6.0)
5
31
 
data/README.md CHANGED
@@ -405,14 +405,12 @@ tag.creator = blogs.author.get(name: 'phil')
405
405
  tag.attributes[:creator] #=> { 'id' => 2, 'name' => 'phil' }
406
406
  ```
407
407
 
408
- Foreign keys can be updated with with the association writer by aliasing the original writer and accessing the
409
- underlying attributes.
408
+ Foreign keys can be updated by overriding the association writer.
410
409
 
411
410
  ```ruby
412
411
  Blog::Tag.class_eval do
413
- alias cistern_creator= creator=
414
412
  def creator=(creator)
415
- self.cistern_creator = creator
413
+ super
416
414
  self.author_id = attributes[:creator][:id]
417
415
  end
418
416
  end
@@ -1,6 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
  module Cistern::Associations
3
3
 
4
+ def self.extended(klass)
5
+ def klass.association_overlay
6
+ @association_overlay ||= const_set(:Associations, Module.new)
7
+ end
8
+
9
+ klass.send(:include, klass.association_overlay)
10
+
11
+ super
12
+ end
13
+
4
14
  # Lists the associations defined on the resource
5
15
  # @return [Hash{Symbol=>Array}] mapping of association type to name
6
16
  def associations
@@ -17,25 +27,32 @@ module Cistern::Associations
17
27
  # identity :registration_id
18
28
  # has_many :lawyers, -> { cistern.associates(firm_id: identity) }
19
29
  # end
20
- def has_many(name, scope)
30
+ def has_many(name, *args, &block)
21
31
  name_sym = name.to_sym
22
32
 
23
33
  reader_method = name
24
34
  writer_method = "#{name}="
25
35
 
26
- attribute name, type: :array
36
+ options = args.last.is_a?(::Hash) ? args.pop : {}
37
+ scope = args.first || block
27
38
 
28
- define_method reader_method do
29
- collection = instance_exec(&scope)
30
- records = attributes[name_sym] || []
39
+ attribute name_sym, options.merge(writer: false, reader: false, type: :array)
31
40
 
32
- collection.load(records) if records.any?
33
- collection
41
+ association_overlay.module_eval do
42
+ define_method reader_method do
43
+ collection = instance_exec(&scope)
44
+ records = attributes[name_sym] || []
45
+
46
+ collection.load(records) if records.any?
47
+ collection
48
+ end
34
49
  end
35
50
 
36
- define_method writer_method do |models|
37
- attributes[name] = Array(models).map do |model|
38
- model.respond_to?(:attributes) ? model.attributes : model
51
+ association_overlay.module_eval do
52
+ define_method writer_method do |models|
53
+ attributes[name] = Array(models).map do |model|
54
+ model.respond_to?(:attributes) ? model.attributes : model
55
+ end
39
56
  end
40
57
  end
41
58
 
@@ -51,24 +68,31 @@ module Cistern::Associations
51
68
  # identity :registration_id
52
69
  # belongs_to :leader, -> { cistern.employees.get(:ceo) }
53
70
  # end
54
- def belongs_to(name, block)
71
+ def belongs_to(name, *args, &block)
55
72
  name_sym = name.to_sym
56
73
 
57
74
  reader_method = name
58
75
  writer_method = "#{name}="
59
76
 
60
- attribute name_sym
77
+ options = args.last.is_a?(::Hash) ? args.pop : {}
78
+ scope = args.first || block
79
+
80
+ attribute name_sym, options.merge(writer: false, reader: false)
61
81
 
62
- define_method reader_method do
63
- model = instance_exec(&block)
64
- attributes[name_sym] = model.attributes
65
- model
82
+ association_overlay.module_eval do
83
+ define_method reader_method do
84
+ model = instance_exec(&scope)
85
+ attributes[name_sym] = model.attributes
86
+ model
87
+ end
66
88
  end
67
89
 
68
- define_method writer_method do |model|
69
- data = model.respond_to?(:attributes) ? model.attributes : model
70
- attributes[name_sym] = data
71
- model
90
+ association_overlay.module_eval do
91
+ define_method writer_method do |model|
92
+ data = model.respond_to?(:attributes) ? model.attributes : model
93
+ attributes[name_sym] = data
94
+ model
95
+ end
72
96
  end
73
97
 
74
98
  associations[:belongs_to] << name_sym
@@ -55,8 +55,8 @@ module Cistern::Attributes
55
55
 
56
56
  attributes[name_sym] = options
57
57
 
58
- define_attribute_reader(name_sym, options)
59
- define_attribute_writer(name_sym, options)
58
+ define_attribute_reader(name_sym, options) unless options[:reader] == false
59
+ define_attribute_writer(name_sym, options) unless options[:writer] == false
60
60
 
61
61
  name_sym
62
62
  end
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = '2.7.0'
2
+ VERSION = '2.7.1'
3
3
  end
@@ -45,6 +45,24 @@ describe Cistern::Associations do
45
45
  expect(sample.associate).to eq(belongs_to)
46
46
  end
47
47
 
48
+ it 'accepts attribute options' do
49
+ subject.class_eval do
50
+ belongs_to :other_associates, -> { Sample::Associate.new(id: 3) }, alias: 'others'
51
+ end
52
+
53
+ expect(subject.attributes[:other_associates][:aliases]).to contain_exactly(:others)
54
+ end
55
+
56
+ it 'accepts a scope in block form' do
57
+ subject.class_eval do
58
+ belongs_to :other_associates, alias: 'others' do
59
+ Sample::Associate.new(id: 3)
60
+ end
61
+ end
62
+
63
+ expect(subject.new.other_associates).to eq(Sample::Associate.new(id: 3))
64
+ end
65
+
48
66
  describe '{belongs_to}=' do
49
67
  it 'accepts a model' do
50
68
  sample = subject.new(id: 1, associate_id: 2)
@@ -62,7 +80,7 @@ describe Cistern::Associations do
62
80
  expect(sample.attributes[:associate]).to eq(id: 2)
63
81
  end
64
82
 
65
- it 'allows for overrides' do
83
+ it 'allows for aliased overrides' do
66
84
  subject.class_eval do
67
85
  alias cistern_associate= associate=
68
86
  def associate=(associate)
@@ -79,6 +97,23 @@ describe Cistern::Associations do
79
97
  sample.associate = belongs_to
80
98
  }.to change(sample, :associate_id).to(2)
81
99
  end
100
+
101
+ it 'allows for overrides using super' do
102
+ subject.class_eval do
103
+ def associate=(associate)
104
+ super
105
+ self.associate_id = attributes[:associate][:id]
106
+ end
107
+ end
108
+
109
+ sample = subject.new(id: 1, associate_id: 3)
110
+
111
+ belongs_to = Sample::Associate.new(id: 2)
112
+
113
+ expect {
114
+ sample.associate = belongs_to
115
+ }.to change(sample, :associate_id).to(2)
116
+ end
82
117
  end
83
118
  end
84
119
 
@@ -128,6 +163,24 @@ describe Cistern::Associations do
128
163
  expect(model.associates.records).to contain_exactly(Sample::Associate.new(id: 3))
129
164
  end
130
165
 
166
+ it 'accepts attribute options' do
167
+ subject.class_eval do
168
+ has_many :other_associates, -> { Sample::Associates.new }, alias: 'others'
169
+ end
170
+
171
+ expect(subject.attributes[:other_associates][:aliases]).to contain_exactly(:others)
172
+ end
173
+
174
+ it 'accepts a scope in block form' do
175
+ subject.class_eval do
176
+ has_many :other_associates, alias: 'others' do
177
+ Sample::Associates.new(associate_id: 1)
178
+ end
179
+ end
180
+
181
+ expect(subject.new.other_associates).to eq(Sample::Associates.new(associate_id: 1))
182
+ end
183
+
131
184
  describe '{has_many}=' do
132
185
  it 'accepts models' do
133
186
  model = subject.new(associate_id: 2)
@@ -226,6 +226,24 @@ describe Cistern::Attributes, 'parsing' do
226
226
  expect(subject.new(default: 'now im a different squash').default).to eq('now im a different squash')
227
227
  end
228
228
 
229
+ it 'can skip reader generation' do
230
+ subject.class_eval do
231
+ attribute :default, reader: false
232
+ end
233
+
234
+ expect(subject.new).not_to respond_to(:default)
235
+ expect(subject.new).to respond_to(:default=)
236
+ end
237
+
238
+ it 'can skip writer generation' do
239
+ subject.class_eval do
240
+ attribute :default, writer: false
241
+ end
242
+
243
+ expect(subject.new).to respond_to(:default)
244
+ expect(subject.new).not_to respond_to(:default=)
245
+ end
246
+
229
247
  context 'allowing the same alias for multiple attributes' do
230
248
  before {
231
249
  subject.class_eval do
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.7.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: API client framework extracted from Fog
14
14
  email: