Class: Spree::LoyaltyPointsTransaction

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
TransactionsTotalValidation
Defined in:
app/models/spree/loyalty_points_transaction.rb

Constant Summary collapse

TRANSACTION_TYPES =
['Spree::LoyaltyPointsCreditTransaction', 'Spree::LoyaltyPointsDebitTransaction']
CLASS_TO_TRANSACTION_TYPE =
{ 'Spree::LoyaltyPointsCreditTransaction' => 'Credit', 'Spree::LoyaltyPointsDebitTransaction' => 'Debit'}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TransactionsTotalValidation

#net_transactions_sum, #validate_transactions_total_range

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



26
27
28
# File 'app/models/spree/loyalty_points_transaction.rb', line 26

def self.ransackable_associations(_auth_object = nil)
  %w[user source]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object

Spree 5.2(Ransack 4.x)は検索・ソート対象を明示的に allowlist することを要求する。 ActiveRecord::Base 継承で Spree::Core::Ransackable を含まないため、Ransack 標準の ransackable_attributes / ransackable_associations をオーバーライドして許可する。



22
23
24
# File 'app/models/spree/loyalty_points_transaction.rb', line 22

def self.ransackable_attributes(_auth_object = nil)
  %w[id loyalty_points type user_id source_id source_type balance comment transaction_id created_at updated_at]
end

Instance Method Details

#transaction_typeObject



30
31
32
# File 'app/models/spree/loyalty_points_transaction.rb', line 30

def transaction_type
  CLASS_TO_TRANSACTION_TYPE[type]
end