Sha256: 9a16a51a3b58a95bebde972cd550ccac061932cf4e5ad499e085129ffdbaac57

Contents?: true

Size: 639 Bytes

Versions: 4

Compression:

Stored size: 639 Bytes

Contents

module Happy
  module Utils
    class AppSpawner
      attr_reader :options

      def initialize(options = {})
        @app = nil
        @options = {
          :scripts => './app/*.rb'
        }.merge(options)
      end

      def call(env)
        app.call(env)
      end

      def app
        @app = reload_app? ? load_app : @app
      end

      def load_app
        Happy::Controller.build.tap do |klass|
          Dir[options[:scripts]].each do |file|
            klass.instance_eval File.read(file)
          end
        end
      end

      def reload_app?
        !Happy.env.production? || @app.nil?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
happy-0.1.0.pre11 lib/happy/utils/app_spawner.rb
happy-0.1.0.pre10 lib/happy/utils/app_spawner.rb
happy-0.1.0.pre9 lib/happy/utils/app_spawner.rb
happy-0.1.0.pre8 lib/happy/utils/app_spawner.rb