Class: Comable::Shipment

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Ransackable
Defined in:
app/models/comable/shipment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.state_namesObject


55
56
57
# File 'app/models/comable/shipment.rb', line 55

def state_names
  state_machine.states.keys
end

Instance Method Details

#can_ship?Boolean

Returns:

  • (Boolean)

86
87
88
# File 'app/models/comable/shipment.rb', line 86

def can_ship?
  ready? && order.paid? && order.completed?
end

#complete!Object


74
75
76
# File 'app/models/comable/shipment.rb', line 74

def complete!
  touch :completed_at
end

#completed?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'app/models/comable/shipment.rb', line 66

def completed?
  completed_at?
end

#current_feeObject


94
95
96
# File 'app/models/comable/shipment.rb', line 94

def current_fee
  shipment_method.try(:fee) || 0
end

#nameObject


90
91
92
# File 'app/models/comable/shipment.rb', line 90

def name
  shipment_method.try(:name) || Comable.t(:normal_shipment)
end

#ready!Object


70
71
72
# File 'app/models/comable/shipment.rb', line 70

def ready!
  shipment_items.each(&:ready!)
end

#restock!Object


78
79
80
# File 'app/models/comable/shipment.rb', line 78

def restock!
  shipment_items.each(&:restock!)
end

#stated?(target_state) ⇒ Boolean

Returns:

  • (Boolean)

60
61
62
63
64
# File 'app/models/comable/shipment.rb', line 60

def stated?(target_state)
  target_state_index = self.class.state_names.index(target_state.to_sym)
  current_state_index = self.class.state_names.index(state_name)
  target_state_index < current_state_index
end

#unstock!Object


82
83
84
# File 'app/models/comable/shipment.rb', line 82

def unstock!
  shipment_items.each(&:unstock!)
end