Class: Plum::Site

Inherits:
ApplicationRecord show all
Defined in:
app/models/plum/site.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.first_or_create_standalone!(skip_defaults: false) ⇒ Object



26
27
28
# File 'app/models/plum/site.rb', line 26

def self.first_or_create_standalone!(skip_defaults: false)
  first_or_create!(name: "My Site", theme_name: "default", skip_defaults: skip_defaults)
end

.for_owner!(owner, attributes = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/plum/site.rb', line 30

def self.for_owner!(owner, attributes = {})
  unless owner.respond_to?(:persisted?) && owner.persisted?
    raise ArgumentError, "Owner must be a persisted Active Record model"
  end

  find_or_create_by!(owner: owner) do |site|
    site.name = attributes.fetch(:name) { owner_default_name(owner) }
    site.theme_name = attributes.fetch(:theme_name, "default")
    site.skip_defaults = attributes.fetch(:skip_defaults, false)
    site.domain = attributes[:domain] if attributes.key?(:domain)
    site.settings = attributes[:settings] if attributes.key?(:settings)
    site.theme_settings = attributes[:theme_settings] if attributes.key?(:theme_settings)
    site.custom_css = attributes[:custom_css] if attributes.key?(:custom_css)
  end
end

Instance Method Details

#themeObject



46
47
48
# File 'app/models/plum/site.rb', line 46

def theme
  ThemeRegistry.new.fetch(theme_name)
end

#theme_settingsObject



50
51
52
# File 'app/models/plum/site.rb', line 50

def theme_settings
  super || {}
end