Class: Jellyfish::Provisioner

Inherits:
Object
  • Object
show all
Defined in:
lib/jellyfish/provisioner.rb,
lib/jellyfish/provisioner/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order_item) ⇒ Provisioner

Returns a new instance of Provisioner.



15
16
17
# File 'lib/jellyfish/provisioner.rb', line 15

def initialize(order_item)
  @order_item = order_item
end

Instance Attribute Details

#order_itemObject (readonly)

Returns the value of attribute order_item.



5
6
7
# File 'lib/jellyfish/provisioner.rb', line 5

def order_item
  @order_item
end

Class Method Details

.critical_error(order_item, message) ⇒ Object



36
37
38
39
# File 'lib/jellyfish/provisioner.rb', line 36

def self.critical_error(order_item, message)
  order_item.provision_status = :critical
  order_item.status_msg = message
end

.perform(order_item_id, error_method) ⇒ Object

private



21
22
23
24
25
26
27
28
29
# File 'lib/jellyfish/provisioner.rb', line 21

def self.perform(order_item_id, error_method)
  order_item = OrderItem.find(order_item_id)
  yield order_item
rescue => e
  send(error_method, order_item, e.message)
  raise
ensure
  order_item.save!
end

.provision(order_item_id) ⇒ Object



7
8
9
# File 'lib/jellyfish/provisioner.rb', line 7

def self.provision(order_item_id)
  perform(order_item_id, :critical_error) { |order_item| new(order_item).provision }
end

.retire(order_item_id) ⇒ Object



11
12
13
# File 'lib/jellyfish/provisioner.rb', line 11

def self.retire(order_item_id)
  perform(order_item_id, :warning_retirement_error) { |order_item| new(order_item).retire }
end

.warning_retirement_error(order_item, message) ⇒ Object



31
32
33
34
# File 'lib/jellyfish/provisioner.rb', line 31

def self.warning_retirement_error(order_item, message)
  order_item.provision_status = :warning
  order_item.status_msg = "Retirement failed: #{message}"[0..254]
end