Sha256: ed8feec4d204afdb5e71b56e73e6fb654cd91a1b1ecaad2643499ee371539241

Contents?: true

Size: 1.61 KB

Versions: 15

Compression:

Stored size: 1.61 KB

Contents

module Voom
  module Presenters
    class App
      class << self
        include Voom::ContainerMethods
        include Voom::LoggerMethods
        include Voom::Trace
        include Voom::Symbol

        def boot!
          logger.warn(no_roots_message) if presenter_paths.empty?
          presenter_paths.each do |load_path|
            Voom::Presenters::App.load('.', load_path) unless ENV['VOOM_ENV']=='testing'
          end
        end

        def no_roots_message
          <<~MESSAGE
            No root defined to load presenters!
            Add the following to your initializer/boot process:

              Voom::Presenters::Settings.configure do |config|
                config.presenters.root = Rails.root.join('app')
              end
          MESSAGE
        end

        def register(name:, presenter: nil, &block)
          raise Errors::MissingArgument,
                'A presenter class, proc, lambda or a block must be provided!' unless block_given? || presenter
          container.register(sym_to_str(name), Voom::Presenters::ContainerItem.new(ui: block || presenter), {})
        end

        def load(dir='app', root=ENV['VOOM_ROOT']||File.expand_path("../../../", __FILE__))
          path = File.expand_path(dir, root)
          trace {"Loading Presenters from: #{path}"}
          Presenters::DSL.load(File.expand_path(dir, root))
          Presenters::DSL.finalize
        end

        def reset!
          super
          Presenters::DSL.reset!
        end

        private

        def presenter_paths
          Array(Voom::Presenters::Settings.config.presenters.root)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
voom-presenters-0.2.0 lib/voom/presenters/app.rb
voom-presenters-0.1.13 lib/voom/presenters/app.rb
voom-presenters-0.1.12 lib/voom/presenters/app.rb
voom-presenters-0.1.11 lib/voom/presenters/app.rb
voom-presenters-0.1.10 lib/voom/presenters/app.rb
voom-presenters-0.1.9 lib/voom/presenters/app.rb
voom-presenters-0.1.8 lib/voom/presenters/app.rb
voom-presenters-0.1.7 lib/voom/presenters/app.rb
voom-presenters-0.1.6 lib/voom/presenters/app.rb
voom-presenters-0.1.5 lib/voom/presenters/app.rb
voom-presenters-0.1.4 lib/voom/presenters/app.rb
voom-presenters-0.1.3 lib/voom/presenters/app.rb
voom-presenters-0.1.2 lib/voom/presenters/app.rb
voom-presenters-0.1.1 lib/voom/presenters/app.rb
voom-presenters-0.1.0 lib/voom/presenters/app.rb