cistern 2.7.0 → 2.7.1
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 +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +2 -4
- data/lib/cistern/associations.rb +44 -20
- data/lib/cistern/attributes.rb +2 -2
- data/lib/cistern/version.rb +1 -1
- data/spec/associations_spec.rb +54 -1
- data/spec/attributes_spec.rb +18 -0
- 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: fd667c59a902c0cfb27b3d8f9f07a9fdc79f42cf
|
4
|
+
data.tar.gz: f37b9ac705677e8a16e8ca777f5032871ca73d72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
413
|
+
super
|
416
414
|
self.author_id = attributes[:creator][:id]
|
417
415
|
end
|
418
416
|
end
|
data/lib/cistern/associations.rb
CHANGED
@@ -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,
|
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
|
-
|
36
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
37
|
+
scope = args.first || block
|
27
38
|
|
28
|
-
|
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
|
-
|
33
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
data/lib/cistern/attributes.rb
CHANGED
@@ -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
|
data/lib/cistern/version.rb
CHANGED
data/spec/associations_spec.rb
CHANGED
@@ -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)
|
data/spec/attributes_spec.rb
CHANGED
@@ -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.
|
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-
|
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:
|