Class: Auctify::Bid
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Auctify::Bid
- Defined in:
- app/models/auctify/bid.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #auction ⇒ Object
- #bade_at ⇒ Object
- #bidder ⇒ Object
- #bidder=(auctified_model) ⇒ Object
- #cancel! ⇒ Object
- #configuration ⇒ Object
- #limit ⇒ Object
- #price_is_not_bigger_then_max_price ⇒ Object
- #price_is_rounded ⇒ Object
- #with_limit? ⇒ Boolean
Instance Method Details
#<=>(other) ⇒ Object
16 17 18 19 20 21 |
# File 'app/models/auctify/bid.rb', line 16 def <=>(other) r = (self.price <=> other.price) r = (self.created_at <=> other.created_at) if r.zero? r = (self.id <=> other.id) if r.zero? r end |
#auction ⇒ Object
61 62 63 |
# File 'app/models/auctify/bid.rb', line 61 def auction registration&.auction end |
#bade_at ⇒ Object
37 38 39 |
# File 'app/models/auctify/bid.rb', line 37 def bade_at created_at end |
#bidder ⇒ Object
57 58 59 |
# File 'app/models/auctify/bid.rb', line 57 def bidder @bidder ||= registration&.bidder end |
#bidder=(auctified_model) ⇒ Object
51 52 53 54 55 |
# File 'app/models/auctify/bid.rb', line 51 def bidder=(auctified_model) errors.add(:bidder, :not_auctified) unless auctified_model.class.included_modules.include?(Auctify::Behavior::Buyer) raise "There is already registration for this bid!" if registration.present? @bidder = auctified_model end |
#cancel! ⇒ Object
23 24 25 26 27 |
# File 'app/models/auctify/bid.rb', line 23 def cancel! update!(cancelled: true) auction.recalculate_bidding! end |
#configuration ⇒ Object
65 66 67 |
# File 'app/models/auctify/bid.rb', line 65 def configuration Auctify.configuration end |
#limit ⇒ Object
33 34 35 |
# File 'app/models/auctify/bid.rb', line 33 def limit max_price end |
#price_is_not_bigger_then_max_price ⇒ Object
41 42 43 |
# File 'app/models/auctify/bid.rb', line 41 def price_is_not_bigger_then_max_price errors.add(:price, :must_be_lower_or_equal_max_price) if max_price && max_price < price end |
#price_is_rounded ⇒ Object
45 46 47 48 49 |
# File 'app/models/auctify/bid.rb', line 45 def price_is_rounded round_to = configuration.require_bids_to_be_rounded_to errors.add(:price, :must_be_rounded_to, { round_to: round_to }) if price && (price != round_it_to(price, round_to)) errors.add(:max_price, :must_be_rounded_to, { round_to: round_to }) if max_price && (max_price != round_it_to(max_price, round_to)) end |
#with_limit? ⇒ Boolean
29 30 31 |
# File 'app/models/auctify/bid.rb', line 29 def with_limit? limit.present? end |