Class: Spree::Base
Constant Summary
Constants included
from PrefixedId
PrefixedId::SQIDS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from PrefixedId
#assign_attributes, decode_prefixed_id, #prefixed_id, prefixed_id?, #to_param
#event_context, #event_payload, #event_prefix, #event_serializer_class, #publish_event
#store_integration, #store_integrations
#serialized_preferences
#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_change, #preference_default, #preference_deprecated, #preference_type, #preferences_of_type, #restore_preferences_for, #set_preference
Class Method Details
.api_type ⇒ Object
Public-API shorthand for this class, used as the ‘type` value on the wire (e.g. `“currency”` for `Spree::Promotion::Rules::Currency`, `“flat_rate”` for `Spree::Calculator::FlatRate`). Defaults to the demodulized + underscored leaf; override on a subclass when the wire format should stay stable across class renames.
85
86
87
|
# File 'app/models/spree/base.rb', line 85
def self.api_type
to_s.demodulize.underscore
end
|
.belongs_to_required_by_default ⇒ Object
30
31
32
|
# File 'app/models/spree/base.rb', line 30
def self.belongs_to_required_by_default
false
end
|
.for_store(store) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'app/models/spree/base.rb', line 34
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_inversing ⇒ Object
53
54
55
|
# File 'app/models/spree/base.rb', line 53
def self.has_many_inversing
false
end
|
.json_api_columns ⇒ Object
66
67
68
|
# File 'app/models/spree/base.rb', line 66
def self.json_api_columns
column_names.reject { |c| c.match(/_id$|id|preferences|(.*)password|(.*)token|(.*)api_key|^original_(.*)/) }
end
|
.json_api_permitted_attributes ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'app/models/spree/base.rb', line 70
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_type ⇒ Object
Backwards-compatible alias for ‘.api_type`. Delegates so subclass overrides of `api_type` are honored.
91
92
93
|
# File 'app/models/spree/base.rb', line 91
def self.json_api_type
api_type
end
|
.page(num) ⇒ Object
19
20
21
|
# File 'app/models/spree/base.rb', line 19
def self.page(num)
send Kaminari.config.page_method_name, num
end
|
.spree_base_scopes ⇒ Object
44
45
46
|
# File 'app/models/spree/base.rb', line 44
def self.spree_base_scopes
where(nil)
end
|
.spree_base_uniqueness_scope ⇒ Object
48
49
50
|
# File 'app/models/spree/base.rb', line 48
def self.spree_base_uniqueness_scope
ApplicationRecord.try(:spree_base_uniqueness_scope) || []
end
|
.to_tom_select_json ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'app/models/spree/base.rb', line 95
def self.to_tom_select_json
pluck(:name, :id).map do |name, id|
{
id: id,
name: name
}
end.as_json
end
|
Instance Method Details
#can_be_deleted? ⇒ Boolean
this can overridden in subclasses to disallow deletion
58
59
60
|
# File 'app/models/spree/base.rb', line 58
def can_be_deleted?
true
end
|
#mysql_adapter? ⇒ Boolean
62
63
64
|
# File 'app/models/spree/base.rb', line 62
def mysql_adapter?
ActiveRecord::Base.connection.adapter_name.downcase.include?('mysql')
end
|
#slug_candidates ⇒ Object
Try building a slug based on the following fields in increasing order of specificity.
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/models/spree/base.rb', line 109
def slug_candidates
if defined?(deleted_at) && deleted_at.present?
[
['deleted', :name],
['deleted', :name, :uuid_for_friendly_id]
]
else
[
[:name],
[:name, :uuid_for_friendly_id]
]
end
end
|
#uuid_for_friendly_id ⇒ Object
104
105
106
|
# File 'app/models/spree/base.rb', line 104
def uuid_for_friendly_id
SecureRandom.uuid
end
|