shiftable 0.6.0 → 0.6.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
  SHA256:
3
- metadata.gz: 03d919c64ab0be03ba40c5474cfa7971dda6158ab01df20940bb644c32482b19
4
- data.tar.gz: 3246e28e7578ea7b56ae905c23c675e121a8c71556d127b8ee4a0fbeedcce15b
3
+ metadata.gz: ae22d0c5730e6bde9ad658ee1b8deddb2ca83e8d09cccc560945faf51c796b6a
4
+ data.tar.gz: b8ef6d21e4273b247a4287a31059eb02bed5bafaf3941562ddfc78f798fd139a
5
5
  SHA512:
6
- metadata.gz: b3721c0d437b1ab45deb99f71f7a199fe4c37aae31f86f8443eb2effd1bd07c9d930aa64c4a4b824c7371863c9cb219251e59dc673d9ef40a73551e75c7efc67
7
- data.tar.gz: c0d40a890f89fda5137575d9052131605f33e6a861e6b9e55b6681d89cfeba4f9ac5547cb09c4ab68cb69bafa50a9c6ebc75412152cf8c3bf9e76f90ce80f823
6
+ metadata.gz: 19ab8c6178402cb18788424023d380672a8d4c7597b432703b79f73900950cf353d8fe85702a0fbd09387f3dd61c4276ba69fe0e9e99499bc77b52d8c9bc3b0b
7
+ data.tar.gz: 66d90707da9952a116619e7421127f2c6bad0f4b74558e24ea0da97d7e5670a17960dfabf92ece49ab9cf10bcc60deb9f556f25fc835df656ba9ad1f0f17aa82
data/CHANGELOG.md CHANGED
@@ -12,6 +12,11 @@
12
12
  ### Removed
13
13
 
14
14
 
15
+ ## [0.6.1] - 2021-11-14
16
+ ### Added
17
+
18
+ - Support for using save with bang (`save!`) to raise error when ActiveRecord save fails.
19
+
15
20
  ## [0.6.0] - 2021-11-12
16
21
  ### Added
17
22
 
@@ -73,8 +73,8 @@ module Shiftable
73
73
  define_method(:"#{prefix}shift_#{type}_column") do
74
74
  signature.send("shift_#{type}_column")
75
75
  end
76
- define_method(:"#{prefix}shift_#{type}") do |shift_to:, shift_from:|
77
- signature.shift_data!(shift_to: shift_to, shift_from: shift_from)
76
+ define_method(:"#{prefix}shift_#{type}") do |shift_to:, shift_from:, bang: false|
77
+ signature.shift_data!(shift_to: shift_to, shift_from: shift_from, bang: bang)
78
78
  end
79
79
  end
80
80
  end
@@ -75,14 +75,15 @@ module Shiftable
75
75
  associations[:has_many]
76
76
  end
77
77
 
78
- def shift_data!(shift_to:, shift_from:)
78
+ def shift_data!(shift_to:, shift_from:, bang: false)
79
79
  validate_relationships
80
80
  shifting_rel = ShiftingRelation.new(
81
81
  to: shift_to,
82
82
  from: shift_from,
83
83
  column: shift_column,
84
84
  base: base,
85
- wrapper: wrapper
85
+ wrapper: wrapper,
86
+ bang: bang
86
87
  )
87
88
  shifting_rel.shift do
88
89
  before_shift&.call(shifting_rel)
@@ -96,7 +97,7 @@ module Shiftable
96
97
  # associations[:has_many]
97
98
  # end
98
99
 
99
- def shift_data!(shift_to:, shift_from:)
100
+ def shift_data!(shift_to:, shift_from:, bang: false)
100
101
  validate_relationships
101
102
  shifting_rel = ShiftingPolymorphicRelation.new(
102
103
  to: shift_to,
@@ -107,7 +108,8 @@ module Shiftable
107
108
  id_column: shift_pcx_column
108
109
  },
109
110
  base: base,
110
- wrapper: wrapper
111
+ wrapper: wrapper,
112
+ bang: bang
111
113
  )
112
114
  shifting_rel.shift do
113
115
  before_shift&.call(shifting_rel)
@@ -125,14 +127,15 @@ module Shiftable
125
127
  options[:precheck]
126
128
  end
127
129
 
128
- def shift_data!(shift_to:, shift_from:)
130
+ def shift_data!(shift_to:, shift_from:, bang: false)
129
131
  validate_relationships
130
132
  shifting = ShiftingRecord.new(
131
133
  to: shift_to,
132
134
  from: shift_from,
133
135
  column: shift_column,
134
136
  base: base,
135
- wrapper: wrapper
137
+ wrapper: wrapper,
138
+ bang: bang
136
139
  ) do
137
140
  !precheck || !shift_to.send(has_rel)
138
141
  end
@@ -3,9 +3,13 @@
3
3
  module Shiftable
4
4
  # Gets data to be shifted
5
5
  class Shifting
6
- attr_reader :to, :from, :column, :base, :result, :run_save, :shift_all_wrapper, :shift_each_wrapper
6
+ # Public API
7
+ attr_accessor :result, :bang, :shift_all_wrapper, :shift_each_wrapper
8
+ attr_reader :to, :from
9
+ # Internal API
10
+ attr_reader :column, :base, :run_save
7
11
 
8
- def initialize(to:, from:, column:, base:, wrapper:)
12
+ def initialize(to:, from:, column:, base:, wrapper:, bang:)
9
13
  @to = to
10
14
  @from = from
11
15
  @column = column
@@ -16,6 +20,7 @@ module Shiftable
16
20
  @run_save = true
17
21
  @shift_all_wrapper = wrapper[:all]
18
22
  @shift_each_wrapper = wrapper[:each]
23
+ @bang = bang
19
24
  end
20
25
 
21
26
  # def found?
@@ -47,11 +52,11 @@ module Shiftable
47
52
  if shift_each_wrapper
48
53
  each do |rec|
49
54
  shift_each_wrapper.call(rec) do
50
- rec.save
55
+ bang ? rec.save! : rec.save
51
56
  end
52
57
  end
53
58
  else
54
- each(&:save)
59
+ bang ? each(&:save!) : each(&:save)
55
60
  end
56
61
  end
57
62
 
@@ -33,10 +33,10 @@ module Shiftable
33
33
  def do_save
34
34
  if shift_each_wrapper
35
35
  shift_each_wrapper.call(result) do
36
- result.save
36
+ bang ? result.save! : result.save
37
37
  end
38
38
  else
39
- result.save
39
+ bang ? result.save! : result.save
40
40
  end
41
41
  end
42
42
 
@@ -73,8 +73,8 @@ module Shiftable
73
73
  define_method(:"#{prefix}shift_column") do
74
74
  signature.send("shift_#{signature.type}_column")
75
75
  end
76
- define_method(:"#{prefix}shift_single") do |shift_to:, shift_from:|
77
- signature.shift_data!(shift_to: shift_to, shift_from: shift_from)
76
+ define_method(:"#{prefix}shift_single") do |shift_to:, shift_from:, bang: false|
77
+ signature.shift_data!(shift_to: shift_to, shift_from: shift_from, bang: bang)
78
78
  end
79
79
  end
80
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shiftable
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiftable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-12 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord