Class: TinyAdmin::Store

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/tiny_admin/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#humanize, #params_to_s, #prepare_page, #to_class

Constructor Details

#initialize(settings) ⇒ Store

Returns a new instance of Store.



9
10
11
12
13
# File 'lib/tiny_admin/store.rb', line 9

def initialize(settings)
  @pages = {}
  @resources = {}
  @settings = settings
end

Instance Attribute Details

Returns the value of attribute navbar.



7
8
9
# File 'lib/tiny_admin/store.rb', line 7

def navbar
  @navbar
end

#pagesObject (readonly)

Returns the value of attribute pages.



7
8
9
# File 'lib/tiny_admin/store.rb', line 7

def pages
  @pages
end

#resourcesObject (readonly)

Returns the value of attribute resources.



7
8
9
# File 'lib/tiny_admin/store.rb', line 7

def resources
  @resources
end

#settingsObject (readonly)

Returns the value of attribute settings.



7
8
9
# File 'lib/tiny_admin/store.rb', line 7

def settings
  @settings
end

Instance Method Details

#prepare_sections(sections, logout:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tiny_admin/store.rb', line 15

def prepare_sections(sections, logout:)
  @navbar = sections.each_with_object([]) do |section, list|
    unless section.is_a?(Hash)
      section_class = to_class(section)
      next unless section_class.respond_to?(:to_h)

      section = section_class.to_h
    end

    slug = section[:slug].to_s
    case section[:type]&.to_sym
    when :content
      list << add_content_section(slug, section)
    when :page
      list << add_page_section(slug, section)
    when :resource
      list << add_resource_section(slug, section)
    when :url
      list << add_url_section(slug, section)
    end
  end
  navbar << logout if logout
end