Sha256: 7150a1f8c862a9a7c0cd085550872d49c05b1c2af7a7d631341a961e4db0ece6

Contents?: true

Size: 1.16 KB

Versions: 14

Compression:

Stored size: 1.16 KB

Contents

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

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

    def initialize(name: 'Application Name', logo: Logo.new, company: Company.new, menu_items: [])
      self.name = name
      self.logo = logo
      self.company = company
      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

14 entries across 14 versions & 1 rubygems

Version Path
five-two-nw-olivander-0.1.2.16 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.15 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.14 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.13 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.12 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.11 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.10 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.9 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.8 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.7 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.6 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.5 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.4 lib/olivander/application_context.rb
five-two-nw-olivander-0.1.2.3 lib/olivander/application_context.rb