Sha256: 7f92a95e2cb7d520eafec84c1179548f9c943d07c23fb7d320e1080eacac8010

Contents?: true

Size: 1.27 KB

Versions: 39

Compression:

Stored size: 1.27 KB

Contents

module Olivander
  class ApplicationContext
    attr_accessor :name, :logo, :company, :menu_items, :route_builder, :sign_out_path, :sidebar_background_class

    def self.default
      ctx = ApplicationContext.new
      ctx.company.name = 'Company Name'
      ctx
    end

    def initialize(name: 'Application Name', logo: Logo.new, company: Company.new, sign_out_path: '/sign_out', menu_items: [])
      self.name = name
      self.logo = logo
      self.company = company
      self.sign_out_path = sign_out_path
      self.menu_items = menu_items
    end

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

    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

    class Logo
      attr_accessor :url, :alt

      def initialize(url: nil, alt: 'Logo')
        self.url = url
        self.alt = alt
      end
    end

    class Company
      attr_accessor :name, :url

      def initialize(name: nil, url: nil)
        self.url = url
        self.name = name
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
five-two-nw-olivander-0.2.0.0 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.60 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.59 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.58 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.57 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.56 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.55 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.54 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.53 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.52 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.51 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.50 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.49 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.48 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.47 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.46 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.45 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.44 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.43.a lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.43 lib/olivander/application_context.rb