Class: Auctify::Bid

Inherits:
ApplicationRecord show all
Defined in:
app/models/auctify/bid.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
18
19
20
# File 'app/models/auctify/bid.rb', line 15

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

#auctionObject



60
61
62
# File 'app/models/auctify/bid.rb', line 60

def auction
  registration&.auction
end

#bade_atObject



36
37
38
# File 'app/models/auctify/bid.rb', line 36

def bade_at
  created_at
end

#bidderObject



56
57
58
# File 'app/models/auctify/bid.rb', line 56

def bidder
  @bidder ||= registration&.bidder
end

#bidder=(auctified_model) ⇒ Object



50
51
52
53
54
# File 'app/models/auctify/bid.rb', line 50

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



22
23
24
25
26
# File 'app/models/auctify/bid.rb', line 22

def cancel!
  update!(cancelled: true)

  auction.recalculate_bidding!
end

#configurationObject



64
65
66
# File 'app/models/auctify/bid.rb', line 64

def configuration
  Auctify.configuration
end

#limitObject



32
33
34
# File 'app/models/auctify/bid.rb', line 32

def limit
  max_price
end

#price_is_not_bigger_then_max_priceObject



40
41
42
# File 'app/models/auctify/bid.rb', line 40

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_roundedObject



44
45
46
47
48
# File 'app/models/auctify/bid.rb', line 44

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



28
29
30
# File 'app/models/auctify/bid.rb', line 28

def with_limit?
  limit.present?
end