Sha256: 0734c6ac5d7946c262c2135743ded6918540ad169cb61676520895e0662e5276

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

module RubyApp
  require 'ruby_app/configuration'
  require 'ruby_app/log'
  require 'ruby_app/mixins/configure_mixin'
  require 'ruby_app/mixins/delegate_mixin'
  require 'ruby_app/mixins/hash_mixin'
  require 'ruby_app/session'
  require 'ruby_app/version'

  class Application
    extend RubyApp::Mixins::DelegateMixin
    include RubyApp::Mixins::ConfigureMixin

    attr_reader :options, :environment

    def initialize(options)
      @options = options
      @environment = {}
    end

    def start!
      RubyApp::Log.open!
      RubyApp::Configuration.load!
    end

    def stop!
      RubyApp::Configuration.unload!
      RubyApp::Log.close!
    end

    def self.get
      @@_application ||= nil
    end

    def self.create!(options = {})
      _options = { :application_class => RubyApp::Application,
                   :session_class => RubyApp::Session,
                   :log_path => File.join(RubyApp::ROOT, %w[log application.log]),
                   :configuration_paths => [],
                   :default_language => :en,
                   :translations_paths => [] }.merge(options)
      _options.configuration_paths = [File.join(RubyApp::ROOT, %w[config.yml])] + ( _options.configuration_paths.is_a?(Array) ? _options.configuration_paths : [_options.configuration_paths] )
      _options.translations_paths = [File.join(RubyApp::ROOT, %w[translations])] + ( _options.translations_paths.is_a?(Array) ? _options.translations_paths : [_options.translations_paths] )
      @@_application = _options.application_class.new(_options)
      @@_application.start!
      RubyApp::Log.debug("#{self}##{__method__} options=#{_options.inspect}")
    end

    def self.destroy!
      RubyApp::Log.debug("#{self}##{__method__}")
      @@_application.stop!
      @@_application = nil
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
RubyApp-0.0.58 lib/ruby_app/application.rb
RubyApp-0.0.57 lib/ruby_app/application.rb
RubyApp-0.0.56 lib/ruby_app/application.rb
RubyApp-0.0.55 lib/ruby_app/application.rb
RubyApp-0.0.54 lib/ruby_app/application.rb
RubyApp-0.0.53 lib/ruby_app/application.rb
RubyApp-0.0.52 lib/ruby_app/application.rb