Class: Olivander::ApplicationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/olivander/application_context.rb

Defined Under Namespace

Classes: Company, LoginLogo, Logo

Constant Summary collapse

DEFAULT_APPLICATION_NAME =
'Application Name'.freeze
DEFAULT_SIGN_OUT_PATH =
'/users/sign_out'.freeze
DEFAULT_HEADER_CLASSES =
''.freeze
DEFAULT_LOGO_URL =
'/images/olivander_logo.png'.freeze
DEFAULT_LOGO_ALT =
'Logo Image'.freeze
DEFAULT_LOGIN_LOGO_URL =
'/images/olivander_login_logo.png'.freeze
DEFAULT_LOGIN_LOGO_ALT =
'Login Logo Image'.freeze
DEFAULT_COMPANY_URL =
'/'.freeze
DEFAULT_COMPANY_ALT =
'Company Name'.freeze
DEFAULT_LAYOUT_CLASS =
'hold-transition sidebar-mini layout-fixed'.freeze
DEFAULT_NAV_CLASS =
'navbar-expand navbar-white navbar-light'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ ApplicationContext

Returns a new instance of ApplicationContext.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/olivander/application_context.rb', line 20

def initialize(**kwargs)
  self.name = kwargs[:name] || ENV['OLIVANDER_APP_NAME'] || DEFAULT_APPLICATION_NAME
  self. = kwargs[:logo] || Logo.new(url: kwargs[:logo_url], alt: kwargs[:logo_alt])
  self. = kwargs[:login_logo] || LoginLogo.new(url: kwargs[:login_logo_url], alt: kwargs[:login_logo_alt])
  self.company = kwargs[:company] || Company.new(name: kwargs[:company_name], url: kwargs[:company_url])
  self.sign_out_path = kwargs[:sign_out_path] || DEFAULT_SIGN_OUT_PATH
  self.menu_items = kwargs[:menu_items] || []
  self.nav_container = kwargs[:nav_container] || 'false'.freeze == 'true'.freeze
  self.nav_class = kwargs[:nav_class] || DEFAULT_NAV_CLASS
  self.layout_container = kwargs[:layout_container] || 'false'.freeze == 'true'.freeze
  self.layout_class = kwargs[:layout_class] || DEFAULT_LAYOUT_CLASS
  self.sidebar = kwargs[:sidebar] || 'true' == 'true'.freeze
  begin
    self.route_builder = RouteBuilder.new
  rescue NameError
    self.route_builder = OpenStruct.new(resources: {})
  end
end

Instance Attribute Details

#companyObject

Returns the value of attribute company.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def company
  @company
end

#layout_classObject

Returns the value of attribute layout_class.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def layout_class
  @layout_class
end

#layout_containerObject

Returns the value of attribute layout_container.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def layout_container
  @layout_container
end

#login_logoObject

Returns the value of attribute login_logo.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def 
  @login_logo
end

#logoObject

Returns the value of attribute logo.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def 
  @logo
end

Returns the value of attribute menu_items.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def menu_items
  @menu_items
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def name
  @name
end

Returns the value of attribute nav_class.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def nav_class
  @nav_class
end

Returns the value of attribute nav_container.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def nav_container
  @nav_container
end

#route_builderObject

Returns the value of attribute route_builder.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def route_builder
  @route_builder
end

Returns the value of attribute sidebar.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def sidebar
  @sidebar
end

Returns the value of attribute sidebar_background_class.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def sidebar_background_class
  @sidebar_background_class
end

#sign_out_pathObject

Returns the value of attribute sign_out_path.



3
4
5
# File 'lib/olivander/application_context.rb', line 3

def sign_out_path
  @sign_out_path
end

Instance Method Details

#layout_container?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/olivander/application_context.rb', line 43

def layout_container?
  layout_container == true
end

Returns:

  • (Boolean)


39
40
41
# File 'lib/olivander/application_context.rb', line 39

def nav_container?
  nav_container == true
end

#sidebar?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/olivander/application_context.rb', line 47

def sidebar?
  sidebar == true
end

#visible_modulesObject



51
52
53
54
55
56
57
# File 'lib/olivander/application_context.rb', line 51

def visible_modules
  [].tap do |arr|
    menu_items.each do |menu_item|
      arr << visible_modules_for(menu_item)
    end
  end.flatten
end

#visible_modules_for(menu_item) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/olivander/application_context.rb', line 59

def visible_modules_for(menu_item)
  [].tap do |arr|
    arr << menu_item if menu_item.module? && menu_item.visible
    menu_item.submenu_items.each do |sub|
      arr << visible_modules_for(sub)
    end
  end
end