From 4dfe02bebf80a5dae134884f12e560d5c6bf651d Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 25 Apr 2019 15:09:37 +0200 Subject: [PATCH] improved ruby syntax to match coding rules in some services --- app/services/reservations/reserve.rb | 29 ++++++------ app/services/subscriptions/subscribe.rb | 59 +++++++++++++------------ 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/app/services/reservations/reserve.rb b/app/services/reservations/reserve.rb index 9cb8de571..8bab493e2 100644 --- a/app/services/reservations/reserve.rb +++ b/app/services/reservations/reserve.rb @@ -1,19 +1,20 @@ -module Reservations - class Reserve - attr_accessor :user_id, :operator_id +# frozen_string_literal: true - def initialize(user_id, operator_id) - @user_id = user_id - @operator_id = operator_id - end +# Provides helper methods for Reservation actions +class Reservations::Reserve + attr_accessor :user_id, :operator_id - def pay_and_save(reservation, payment_method, coupon) - reservation.user_id = user_id - if payment_method == :local - reservation.save_with_local_payment(operator_id, coupon) - elsif payment_method == :stripe - reservation.save_with_payment(operator_id, coupon) - end + def initialize(user_id, operator_id) + @user_id = user_id + @operator_id = operator_id + end + + def pay_and_save(reservation, payment_method, coupon) + reservation.user_id = user_id + if payment_method == :local + reservation.save_with_local_payment(operator_id, coupon) + elsif payment_method == :stripe + reservation.save_with_payment(operator_id, coupon) end end end diff --git a/app/services/subscriptions/subscribe.rb b/app/services/subscriptions/subscribe.rb index 3af97c5f7..4e9fb2bc6 100644 --- a/app/services/subscriptions/subscribe.rb +++ b/app/services/subscriptions/subscribe.rb @@ -1,34 +1,35 @@ -module Subscriptions - class Subscribe - attr_accessor :user_id, :operator_id +# frozen_string_literal: true - def initialize(user_id, operator_id) - @user_id = user_id - @operator_id = operator_id - end +# Provides helper methods for Subscription actions +class Subscriptions::Subscribe + attr_accessor :user_id, :operator_id - def pay_and_save(subscription, payment_method, coupon, invoice) - subscription.user_id = user_id - if payment_method == :local - subscription.save_with_local_payment(operator_id, invoice, coupon) - elsif payment_method == :stripe - subscription.save_with_payment(operator_id, invoice, coupon) - end - end + def initialize(user_id, operator_id) + @user_id = user_id + @operator_id = operator_id + end - def extend_subscription(subscription, new_expiration_date, free_days) - return subscription.free_extend(new_expiration_date) if free_days - - new_sub = Subscription.create( - plan_id: subscription.plan_id, - user_id: subscription.user_id, - expiration_date: new_expiration_date - ) - if new_sub.save - new_sub.user.generate_subscription_invoice(operator_id) - return new_sub - end - false + def pay_and_save(subscription, payment_method, coupon, invoice) + subscription.user_id = user_id + if payment_method == :local + subscription.save_with_local_payment(operator_id, invoice, coupon) + elsif payment_method == :stripe + subscription.save_with_payment(operator_id, invoice, coupon) end end -end + + def extend_subscription(subscription, new_expiration_date, free_days) + return subscription.free_extend(new_expiration_date) if free_days + + new_sub = Subscription.create( + plan_id: subscription.plan_id, + user_id: subscription.user_id, + expiration_date: new_expiration_date + ) + if new_sub.save + new_sub.user.generate_subscription_invoice(operator_id) + return new_sub + end + false + end +end \ No newline at end of file