Class: Auctify::Bid

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

Instance Method Summary collapse

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

#auctionObject



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

def auction
  registration&.auction
end

#bade_atObject



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

def bade_at
  created_at
end

#bidderObject



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

#configurationObject



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

def configuration
  Auctify.configuration
end

#limitObject



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

def limit
  max_price
end

#price_is_not_bigger_then_max_priceObject



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_roundedObject



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

Returns:

  • (Boolean)


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

def with_limit?
  limit.present?
end