From b84f49a1c37a0874859ce57439b2efa69c9d296d Mon Sep 17 00:00:00 2001 From: Steve Pettitt Date: Wed, 24 Feb 2016 20:39:26 +0000 Subject: [PATCH] Satisfy style police --- app/helpers/injection_helper.rb | 8 +++- app/models/spree/user_decorator.rb | 2 +- app/serializers/api/order_serializer.rb | 42 ++++++++++--------- .../api/orders_by_distributor_serializer.rb | 29 ++++++------- app/serializers/api/payment_serializer.rb | 22 +++++----- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb index 6c35bc775f..aa5148b394 100644 --- a/app/helpers/injection_helper.rb +++ b/app/helpers/injection_helper.rb @@ -54,8 +54,12 @@ module InjectionHelper def inject_orders_by_distributor # Convert ActiveRecord::Relation to array for serialization data_array = spree_current_user.orders_by_distributor.to_a - data_array.each{|enterprise| enterprise.distributed_orders.each{|order| order.payments.keep_if{|payment| payment.state == "completed"} }} - data_array.sort!{|a,b| b.distributed_orders.length <=> a.distributed_orders.length} + data_array.each do |enterprise| + enterprise.distributed_orders.each do |order| + order.payments.keep_if{ |payment| payment.state == "completed" } + end + end + data_array.sort!{ |a, b| b.distributed_orders.length <=> a.distributed_orders.length } inject_json_ams "orders_by_distributor", data_array, Api::OrdersByDistributorSerializer end diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb index 2578f417cc..6c5027a228 100644 --- a/app/models/spree/user_decorator.rb +++ b/app/models/spree/user_decorator.rb @@ -56,7 +56,7 @@ Spree.user_class.class_eval do # Returns orders and their associated payments for all distributors that have been ordered from def orders_by_distributor - Enterprise.includes(distributed_orders: :payments).where(enterprises: {id: self.enterprises_ordered_from }, spree_orders: {state: 'complete', user_id: self.id}).order('spree_orders.completed_at DESC') + Enterprise.includes(distributed_orders: :payments).where(enterprises: { id: self.enterprises_ordered_from }, spree_orders: { state: 'complete', user_id: self.id }).order('spree_orders.completed_at DESC') end private diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb index 7105e3577b..9d7a453b18 100644 --- a/app/serializers/api/order_serializer.rb +++ b/app/serializers/api/order_serializer.rb @@ -1,29 +1,31 @@ -class Api::OrderSerializer < ActiveModel::Serializer - attributes :number, :completed_at, :total, :state, :shipment_state, :payment_state, :outstanding_balance, :payments, :path +module Api + class OrderSerializer < ActiveModel::Serializer + attributes :number, :completed_at, :total, :state, :shipment_state, :payment_state, :outstanding_balance, :payments, :path - has_many :payments, serializer: Api::PaymentSerializer + has_many :payments, serializer: Api::PaymentSerializer - def completed_at - object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: :long) #.to_formatted_s(:long_ordinal) - end + def completed_at + object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: :long) #.to_formatted_s(:long_ordinal) + end - def total - object.total.to_money.to_s - end + def total + object.total.to_money.to_s + end - def shipment_state - object.shipment_state ? object.shipment_state.humanize : nil # Or a call to t() here? - end + def shipment_state + object.shipment_state ? object.shipment_state.humanize : nil # Or a call to t() here? + end - def payment_state - object.payment_state ? object.payment_state.humanize : nil # Or a call to t() here? - end + def payment_state + object.payment_state ? object.payment_state.humanize : nil # Or a call to t() here? + end - def state - object.state ? object.state.humanize : nil # Or a call to t() here? - end + def state + object.state ? object.state.humanize : nil # Or a call to t() here? + end - def path - Spree::Core::Engine.routes_url_helpers.order_url(object.number, only_path: true) + def path + Spree::Core::Engine.routes_url_helpers.order_url(object.number, only_path: true) + end end end diff --git a/app/serializers/api/orders_by_distributor_serializer.rb b/app/serializers/api/orders_by_distributor_serializer.rb index 3d04bf2a03..b920272df2 100644 --- a/app/serializers/api/orders_by_distributor_serializer.rb +++ b/app/serializers/api/orders_by_distributor_serializer.rb @@ -1,17 +1,18 @@ -class Api::OrdersByDistributorSerializer < ActiveModel::Serializer - attributes :name, :id, :hash, :balance, :logo, :distributed_orders - has_many :distributed_orders, serializer: Api::OrderSerializer +module Api + class OrdersByDistributorSerializer < ActiveModel::Serializer + attributes :name, :id, :hash, :balance, :logo, :distributed_orders + has_many :distributed_orders, serializer: Api::OrderSerializer - def balance - object.distributed_orders.map(&:outstanding_balance).reduce(:+).to_money.to_s + def balance + object.distributed_orders.map(&:outstanding_balance).reduce(:+).to_money.to_s + end + + def hash + object.to_param + end + + def logo + object.logo(:small) if object.logo? + end end - - def hash - object.to_param - end - - def logo - object.logo(:small) if object.logo? - end - end diff --git a/app/serializers/api/payment_serializer.rb b/app/serializers/api/payment_serializer.rb index 505a5a79e1..d48f75a07f 100644 --- a/app/serializers/api/payment_serializer.rb +++ b/app/serializers/api/payment_serializer.rb @@ -1,14 +1,16 @@ -class Api::PaymentSerializer < ActiveModel::Serializer - attributes :amount, :updated_at, :payment_method - def payment_method - object.payment_method.name - end +module Api + class PaymentSerializer < ActiveModel::Serializer + attributes :amount, :updated_at, :payment_method + def payment_method + object.payment_method.name + end - def amount - object.amount.to_money.to_s - end + def amount + object.amount.to_money.to_s + end - def updated_at - I18n.l(object.updated_at, format: :long) + def updated_at + I18n.l(object.updated_at, format: :long) + end end end