Class: Spree::Base

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

Class Method Summary collapse

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference

Class Method Details

.belongs_to_required_by_defaultObject



21
22
23
# File 'app/models/spree/base.rb', line 21

def self.belongs_to_required_by_default
  false
end

.for_store(store) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'app/models/spree/base.rb', line 25

def self.for_store(store)
  plural_model_name = model_name.plural.gsub(/spree_/, '').to_sym

  if store.respond_to?(plural_model_name)
    store.send(plural_model_name)
  else
    self
  end
end

.has_many_inversingObject



44
45
46
# File 'app/models/spree/base.rb', line 44

def self.has_many_inversing
  false
end

.json_api_columnsObject



48
49
50
# File 'app/models/spree/base.rb', line 48

def self.json_api_columns
  column_names.reject { |c| c.match(/_id$|id|preferences|(.*)password|(.*)token|(.*)api_key/) }
end

.json_api_permitted_attributesObject



52
53
54
55
56
57
58
59
60
# File 'app/models/spree/base.rb', line 52

def self.json_api_permitted_attributes
  skipped_attributes = %w[id]

  if included_modules.include?(CollectiveIdea::Acts::NestedSet::Model)
    skipped_attributes.push('lft', 'rgt', 'depth')
  end

  column_names.reject { |c| skipped_attributes.include?(c.to_s) }
end

.json_api_typeObject



62
63
64
# File 'app/models/spree/base.rb', line 62

def self.json_api_type
  to_s.demodulize.underscore
end

.page(num) ⇒ Object



14
15
16
# File 'app/models/spree/base.rb', line 14

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

.spree_base_scopesObject



35
36
37
# File 'app/models/spree/base.rb', line 35

def self.spree_base_scopes
  where(nil)
end

.spree_base_uniqueness_scopeObject



39
40
41
# File 'app/models/spree/base.rb', line 39

def self.spree_base_uniqueness_scope
  ApplicationRecord.try(:spree_base_uniqueness_scope) || []
end