Class: Spree::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Preferences::Preferable, RansackableAttributes
Defined in:
app/models/spree/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

.display_includesObject

Provides a scope that should be included any time products are fetched with the intention of displaying to the user.

Allows individual stores to include any active record scopes or joins when products are displayed.



37
38
39
# File 'app/models/spree/base.rb', line 37

def self.display_includes
  where(nil)
end

.page(num) ⇒ Object



25
26
27
# File 'app/models/spree/base.rb', line 25

def self.page(num)
  send Kaminari.config.page_method_name, num
end

.preference(*args) ⇒ Object

Only run preference initialization on models which requires it. Improves performance of record initialization slightly.



17
18
19
20
21
22
# File 'app/models/spree/base.rb', line 17

def self.preference(*args)
  # after_initialize can be called multiple times with the same symbol, it
  # will only be called once on initialization.
  after_initialize :initialize_preference_defaults
  super
end

Instance Method Details

#initialize_preference_defaultsObject



9
10
11
12
13
# File 'app/models/spree/base.rb', line 9

def initialize_preference_defaults
  if has_attribute?(:preferences)
    self.preferences = default_preferences.merge(preferences)
  end
end