class Lita::Interactors::ChangeValue
Set the given value to a user
Attributes
data[R]
Public Class Methods
new(handler, data)
click to toggle source
# File lib/lita/interactors/change_value.rb, line 12 def initialize(handler, data) @handler = handler @data = data end
Public Instance Methods
perform()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 17 def perform if service_exists? update_costumer_if_exist else @error = msg_not_found(service_name: name) end self end
Private Instance Methods
change_value()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 70 def change_value old_value = customer[:value] customer[:value] = customer_value @message = I18n.t('lita.handlers.service.set_value.success', old_value: old_value, customer_name: customer_name, customer_value: customer_value) end
customer()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 44 def customer service[:customers][customer_name.to_sym] end
customer_exists?()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 52 def customer_exists? service[:customers].keys.include?(customer_name.to_sym) end
customer_name()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 32 def customer_name @customer_name ||= data[2].delete('@') end
customer_value()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 36 def customer_value @customer_value ||= data[3].to_i end
name()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 28 def name @name ||= data[1] end
service()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 40 def service @service ||= repository.find(name) end
service_exists?()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 48 def service_exists? repository.exists?(name) end
update_costumer_if_exist()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 56 def update_costumer_if_exist if customer_exists? update_customer_value else @error = msg_customer_not_found(service_name: name, customer_name: customer_name) end end
update_customer_value()
click to toggle source
# File lib/lita/interactors/change_value.rb, line 65 def update_customer_value change_value repository.update(service) end