Class: Comable::Shipment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Shipment
- Includes:
- Ransackable
- Defined in:
- app/models/comable/shipment.rb
Class Method Summary collapse
Instance Method Summary collapse
- #can_ship? ⇒ Boolean
- #complete! ⇒ Object
- #completed? ⇒ Boolean
- #current_fee ⇒ Object
- #name ⇒ Object
- #ready! ⇒ Object
- #restock! ⇒ Object
- #stated?(target_state) ⇒ Boolean
- #unstock! ⇒ Object
Class Method Details
.state_names ⇒ Object
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
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
66 67 68 |
# File 'app/models/comable/shipment.rb', line 66 def completed? completed_at? end |
#current_fee ⇒ Object
94 95 96 |
# File 'app/models/comable/shipment.rb', line 94 def current_fee shipment_method.try(:fee) || 0 end |
#name ⇒ Object
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
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 |