cistern 2.8.1 → 2.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cistern/associations.rb +17 -8
- data/lib/cistern/version.rb +1 -1
- data/spec/dirty_spec.rb +19 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13428a2696bc1c11c76ec323e498a73268070325702dac6b5107ac16786537a8
|
4
|
+
data.tar.gz: 58c19d84a3d6f0b9fd347a10c916aa925136896f91f49634a9c2bbbcc011ed26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f8642906b69eb047b6f907b786a3a42c14e6313ba177f5c314994abdc652285dabbba8cd594e8661c651f3fbf4e926dd82d788bf8a3ae2fb9a902e25a3ad604
|
7
|
+
data.tar.gz: 406ed32508a96668915a3485e61dc9f7abd9fc68a9989ff9c1f2ccfb16d5646400501fbad4c29cfdd8d6ee82ef3fe9fffc577d947bcdff4eaf510529e090b22f
|
data/lib/cistern/associations.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Cistern::Associations
|
4
|
-
|
5
4
|
def self.extended(klass)
|
6
5
|
def klass.association_overlay
|
7
6
|
@association_overlay ||= const_set(:Associations, Module.new)
|
@@ -15,7 +14,7 @@ module Cistern::Associations
|
|
15
14
|
# Lists the associations defined on the resource
|
16
15
|
# @return [Hash{Symbol=>Array}] mapping of association type to name
|
17
16
|
def associations
|
18
|
-
@associations ||= Hash.new { |h,k| h[k] = [] }
|
17
|
+
@associations ||= Hash.new { |h, k| h[k] = [] }
|
19
18
|
end
|
20
19
|
|
21
20
|
# Define an assocation that references a collection.
|
@@ -51,9 +50,15 @@ module Cistern::Associations
|
|
51
50
|
|
52
51
|
association_overlay.module_eval do
|
53
52
|
define_method writer_method do |models|
|
54
|
-
attributes[
|
55
|
-
|
56
|
-
|
53
|
+
previous_value = attributes[name_sym]
|
54
|
+
new_value =
|
55
|
+
attributes[name_sym] = Array(models).map do |model|
|
56
|
+
model.respond_to?(:attributes) ? model.attributes : model
|
57
|
+
end
|
58
|
+
|
59
|
+
changed!(name_sym, previous_value, new_value)
|
60
|
+
|
61
|
+
new_value
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
@@ -90,9 +95,13 @@ module Cistern::Associations
|
|
90
95
|
|
91
96
|
association_overlay.module_eval do
|
92
97
|
define_method writer_method do |model|
|
93
|
-
|
94
|
-
|
95
|
-
|
98
|
+
previous_value = attributes[name_sym]
|
99
|
+
new_value = model.respond_to?(:attributes) ? model.attributes : model
|
100
|
+
attributes[name_sym] = new_value
|
101
|
+
|
102
|
+
changed!(name_sym, previous_value, new_value)
|
103
|
+
|
104
|
+
new_value
|
96
105
|
end
|
97
106
|
end
|
98
107
|
|
data/lib/cistern/version.rb
CHANGED
data/spec/dirty_spec.rb
CHANGED
@@ -3,18 +3,35 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe 'Cistern::Model#dirty' do
|
6
|
-
subject
|
6
|
+
subject do
|
7
7
|
Class.new(Sample::Model) do
|
8
8
|
identity :id
|
9
9
|
|
10
10
|
attribute :name
|
11
11
|
attribute :properties, type: :array
|
12
12
|
|
13
|
+
has_many :many, -> { [] }
|
14
|
+
belongs_to :one, -> { true }
|
15
|
+
|
13
16
|
def save
|
14
17
|
merge_attributes(attributes)
|
15
18
|
end
|
16
19
|
end
|
17
|
-
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'marks has_many associations as dirty' do
|
23
|
+
model = subject.new(many: [1, 2])
|
24
|
+
expect(model.changed).to be_empty
|
25
|
+
expect { model.many = [3, 4] }.to change { model.dirty? }.to(true)
|
26
|
+
expect(model.changed).to eq(many: [[1, 2], [3, 4]])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'marks belongs_to associations as dirty' do
|
30
|
+
model = subject.new(one: 1)
|
31
|
+
expect(model.changed).to be_empty
|
32
|
+
expect { model.one = 2 }.to change { model.dirty? }.to(true)
|
33
|
+
expect(model.changed).to eq(one: [1, 2])
|
34
|
+
end
|
18
35
|
|
19
36
|
it 'should mark a existing record as dirty' do
|
20
37
|
model = subject.new(id: 1, name: 'steve')
|
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.8.
|
4
|
+
version: 2.8.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: 2018-05-
|
11
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: API client framework extracted from Fog
|
14
14
|
email:
|