Class: TinyAdmin::Settings

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/tiny_admin/settings.rb

Constant Summary collapse

DEFAULTS =
{
  %i[authentication plugin] => Plugins::NoAuth,
  %i[authentication login] => Views::Pages::SimpleAuthLogin,
  %i[authorization_class] => Plugins::Authorization,
  %i[components field_value] => Views::Components::FieldValue,
  %i[components flash] => Views::Components::Flash,
  %i[components head] => Views::Components::Head,
  %i[components navbar] => Views::Components::Navbar,
  %i[components pagination] => Views::Components::Pagination,
  %i[content_page] => Views::Pages::Content,
  %i[helper_class] => Support,
  %i[page_not_allowed] => Views::Pages::PageNotAllowed,
  %i[page_not_found] => Views::Pages::PageNotFound,
  %i[record_not_found] => Views::Pages::RecordNotFound,
  %i[repository] => Plugins::ActiveRecordRepository,
  %i[root_path] => '/admin',
  %i[root page] => Views::Pages::Root,
  %i[root title] => 'TinyAdmin',
  %i[sections] => []
}.freeze
OPTIONS =
%i[
  authentication
  authorization_class
  components
  content_page
  extra_styles
  helper_class
  page_not_allowed
  page_not_found
  record_not_found
  repository
  root
  root_path
  sections
  scripts
  style_links
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



46
47
48
# File 'lib/tiny_admin/settings.rb', line 46

def store
  @store
end

Instance Method Details

#[](*path) ⇒ Object



58
59
60
61
# File 'lib/tiny_admin/settings.rb', line 58

def [](*path)
  key, option = fetch_setting(path)
  option[key]
end

#[]=(*path, value) ⇒ Object



63
64
65
66
67
# File 'lib/tiny_admin/settings.rb', line 63

def []=(*path, value)
  key, option = fetch_setting(path)
  option[key] = value
  convert_value(key, value)
end

#load_settingsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tiny_admin/settings.rb', line 69

def load_settings
  # default values
  DEFAULTS.each do |(option, param), default|
    if param
      self[option] ||= {}
      self[option][param] ||= default
    else
      self[option] ||= default
    end
  end

  @store ||= TinyAdmin::Store.new(self)
  self.root_path = '/' if root_path == ''

  if authentication[:plugin] <= Plugins::SimpleAuth
    logout_path = "#{root_path}/auth/logout"
    authentication[:logout] ||= TinyAdmin::Section.new(name: 'logout', slug: 'logout', path: logout_path)
  end
  store.prepare_sections(sections, logout: authentication[:logout])
end

#reset!Object



90
91
92
# File 'lib/tiny_admin/settings.rb', line 90

def reset!
  @options = {}
end