auctify 1.1.0 → 1.1.3

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: 13a52b4af50580a4b82abdb1c7fd04686803f3a59d648b2a0fb18bc7acb46875
4
- data.tar.gz: c33891089eb4f6e53d101b033442dc56dd62966a2b0aef5d1173e73c0070335d
3
+ metadata.gz: 14832525cab9835407bccb94056500037fe39da17a9ea311f7053ce4adf48255
4
+ data.tar.gz: 522647a33fa236dd02c2980ecde719508bd83f21db2c0ffa38d1d77ce104d002
5
5
  SHA512:
6
- metadata.gz: 33f938020a0879f29ce53ac4f0a926138f9c904cdcb435ecdf4ac79119300e450394861c12f611e6248ac5136ab7e94516a3232d9451bf339a682509ce2eac92
7
- data.tar.gz: a68e770af42e0c5be75ff52e47bccc428d80be1c49b5744623cd26d0c0aa5b01d6700d5e385f1e0ad3e41448aeaf7ff66efbb8b5fd0414b3c562e35041b64776
6
+ metadata.gz: 803112a2c554cb95f1eb818911ea4a92d4377306ba936ac5190101f8463a5378d225a5c260a50e01e8cc0f379ddd87b1d57902d186a8469c7baa34dee991f23a
7
+ data.tar.gz: ee8f293dbba3adc69a730d208b4973ebf7d9609d326bca03eda616ca668edfb792b2d4d9b09bef211a5c08db221da2befcd507d9d3f0844c5d8de1e774db46d8
data/README.md CHANGED
@@ -121,6 +121,9 @@ end
121
121
  ```
122
122
 
123
123
  3. ### Configure
124
+ Enqueuing of `BiddingCloserJob` (for each auction) is done by peridically performed `Auctify::EnsureAuctionsClosingJob`.
125
+ This is up to You how you run it, but interval between runs must be shorter than `Auctify.configuration.auction_prolonging_limit_in_seconds`.
126
+
124
127
  - optional
125
128
  ```ruby
126
129
  Auctify.configure do |config|
@@ -17,20 +17,14 @@ module Auctify
17
17
  def bids
18
18
  if params[:confirmation] == "1"
19
19
  if @auction.bid!(new_bid)
20
- if params[:dont_confirm_bids] == "1"
21
- # use SQL update in case of some obscure invalid attributes
22
- current_user.bidder_registrations
23
- .where(auction: @auction)
24
- .update_all(dont_confirm_bids: true)
25
- end
26
-
27
20
  @auction.reload
28
21
 
29
- winning_bid_id = @auction.winning_bid.try(:id)
30
- overbid_by_limit = winning_bid_id && new_bid.id && winning_bid_id != new_bid.id
22
+ store_dont_confirm_bids
31
23
 
32
- render_record @auction, success: true, overbid_by_limit: overbid_by_limit
24
+ render_record @auction, success: true, overbid_by_limit: overbid_by_limit?(new_bid)
33
25
  else
26
+ store_dont_confirm_bids
27
+
34
28
  render_record @auction, bid: new_bid, status: 400
35
29
  end
36
30
  else
@@ -68,6 +62,23 @@ module Auctify
68
62
  overbid_by_limit: overbid_by_limit).show
69
63
  }, status: status
70
64
  end
65
+
66
+ def store_dont_confirm_bids
67
+ if params[:dont_confirm_bids] == "1"
68
+ # use SQL update in case of some obscure invalid attributes
69
+ bidder_regs = current_user.bidder_registrations.where(auction: @auction)
70
+ bidder_regs.update_all(dont_confirm_bids: true) if bidder_regs.present?
71
+ end
72
+ end
73
+
74
+ def overbid_by_limit?(new_bid)
75
+ winning_bid = @auction&.winning_bid
76
+ return false unless winning_bid
77
+ return false if new_bid.id.blank? || winning_bid.id.blank?
78
+ return false if winning_bid.registration_id == new_bid.registration_id # do not notify bidder about overbidding itself
79
+
80
+ winning_bid != new_bid
81
+ end
71
82
  end
72
83
  end
73
84
  end
@@ -9,7 +9,7 @@ module Auctify
9
9
  .where("currently_ends_at <= ?", Time.current + checking_period_to_future)
10
10
  auctions.each do |auction|
11
11
  if auction.currently_ends_at <= Time.current
12
- Auctify::BiddingCloserJob.perform_now(auction_id: auction.id)
12
+ Auctify::BiddingCloserJob.perform_later(auction_id: auction.id)
13
13
  else
14
14
  Auctify::BiddingCloserJob.set(wait_until: auction.currently_ends_at).perform_later(auction_id: auction.id)
15
15
  end
@@ -216,6 +216,14 @@ module Auctify
216
216
  bidding_result.current_minimal_bid
217
217
  end
218
218
 
219
+ def minimal_bid_increase_amount_at(price, respect_first_bid: true)
220
+ return 0 if respect_first_bid && ordered_applied_bids.blank? # first bid can equal opening price
221
+ return Auctify.configuration.require_bids_to_be_rounded_to if bid_steps_ladder.blank?
222
+
223
+ _range, increase_step = bid_steps_ladder.detect { |range, step| range.cover?(price) }
224
+ increase_step
225
+ end
226
+
219
227
  def current_max_price_for(bidder, bids_array: nil)
220
228
  bids_array ||= ordered_applied_bids.with_limit
221
229
 
@@ -45,17 +45,24 @@ module Auctify
45
45
  end
46
46
 
47
47
  def dates_to_label
48
- if start_date && end_date
49
- if start_date.year == end_date.year
50
- if start_date.month == end_date.month
51
- "#{start_date.strftime('%-d.')}–#{end_date.strftime('%-d. %-m. %y')}"
52
- else
53
- "#{start_date.strftime('%-d. %-m.')} #{end_date.strftime('%-d. %-m. %y')}"
54
- end
48
+ return "" unless start_date && end_date
49
+
50
+ date_strings = []
51
+ if start_date.year == end_date.year
52
+ if start_date.month == end_date.month
53
+ # all inside same month
54
+ date_strings << start_date.strftime("%-d.")
55
55
  else
56
- "#{start_date.strftime('%-d. %-m. %y')} #{end_date.strftime('%-d. %-m. %y')}"
56
+ # all inside same year
57
+ date_strings << start_date.strftime("%-d. %-m.")
57
58
  end
59
+ else
60
+ # crossing years border
61
+ date_strings << start_date.strftime("%-d. %-m. %Y")
58
62
  end
63
+
64
+ date_strings << end_date.strftime("%-d. %-m. %Y")
65
+ date_strings.join(" – ")
59
66
  end
60
67
 
61
68
  def shift_sales_by_minutes!(shift_in_minutes)
@@ -46,8 +46,8 @@ module Auctify
46
46
  def set_price_for_limit_bid
47
47
  return unless bid.price.blank? && bid.with_limit?
48
48
 
49
- if changing_own_limit?
50
- bid.price = winning_bid.price
49
+ if changing_own_limit_when_winning?
50
+ bid.price = [bid.max_price, winning_bid.price].min
51
51
  elsif bid.max_price <= new_current_minimal_bid
52
52
  bid.price = bid.max_price
53
53
  else
@@ -59,7 +59,8 @@ module Auctify
59
59
  @approved_bid ||= begin
60
60
  bid.valid?
61
61
  check_bidder
62
- changing_own_limit? ? check_max_price_increasing : check_price_minimum
62
+ check_max_price_increasing
63
+ check_price_minimum
63
64
  check_same_bidder
64
65
  check_auction_state
65
66
 
@@ -95,7 +96,6 @@ module Auctify
95
96
 
96
97
  def new_current_minimal_bid
97
98
  return current_price if first_bid?
98
-
99
99
  increase_price(current_price)
100
100
  end
101
101
 
@@ -132,11 +132,14 @@ module Auctify
132
132
  end
133
133
 
134
134
  def check_max_price_increasing
135
- bid.errors.add(:bidder, :you_can_only_increase_your_max_price) if bid.max_price.present? && (bid.max_price.to_i <= winning_bid.max_price.to_i)
135
+ return unless changing_own_limit_when_winning?
136
+
137
+ bid.errors.add(:bidder, :you_can_only_increase_your_max_price) if bid.max_price.to_i <= winning_bid.max_price.to_i
136
138
  end
137
139
 
138
140
  def check_price_minimum
139
- if bid.price < new_current_minimal_bid
141
+ minimum = changing_own_limit_when_winning? ? current_price : new_current_minimal_bid
142
+ if bid.price < minimum
140
143
  att = bid.with_limit? ? :max_price : :price
141
144
  bid.errors.add(att,
142
145
  :price_is_bellow_minimal_bid,
@@ -145,7 +148,7 @@ module Auctify
145
148
  end
146
149
 
147
150
  def check_same_bidder
148
- return if overbidding_yourself_allowed? || changing_own_limit?
151
+ return if overbidding_yourself_allowed? || changing_own_limit_when_winning?
149
152
 
150
153
  if winning_bid.present? && same_bidder?(winning_bid, bid)
151
154
  bid.errors.add(:bidder, :you_cannot_overbid_yourself)
@@ -160,7 +163,7 @@ module Auctify
160
163
  end
161
164
 
162
165
  def solve_winner(winning_bid, new_bid)
163
- return if winning_bid.blank? || changing_own_limit?
166
+ return if winning_bid.blank? || changing_own_limit_when_winning?
164
167
 
165
168
  solve_limits_fight(winning_bid, new_bid) if new_bid.with_limit? && winning_bid.with_limit?
166
169
  increase_bid_price(winning_bid, new_bid) if new_bid.with_limit? && !winning_bid.with_limit?
@@ -206,10 +209,7 @@ module Auctify
206
209
  end
207
210
 
208
211
  def increase_price(price)
209
- return price + Auctify.configuration.require_bids_to_be_rounded_to if bid_steps_ladder.blank?
210
-
211
- _range, increase_step = bid_steps_ladder.detect { |range, step| range.cover?(price) }
212
- price + increase_step
212
+ price + auction.minimal_bid_increase_amount_at(price, respect_first_bid: false)
213
213
  end
214
214
 
215
215
  def increase_price_to(overcome:, ceil:)
@@ -224,11 +224,7 @@ module Auctify
224
224
  [running_price, ceil].min
225
225
  end
226
226
 
227
- def bid_steps_ladder
228
- @bid_steps_ladder ||= auction.bid_steps_ladder
229
- end
230
-
231
- def changing_own_limit?
227
+ def changing_own_limit_when_winning?
232
228
  bid.with_limit? && winning_bid.present? && (winning_bid.bidder == bid.bidder)
233
229
  end
234
230
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Auctify
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auctify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - foton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails