Sha256: f16abb51fcdf50575054308fa036bfd7906baf9fac57e4124e55ed34b869173a

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

ENV['RACK_ENV'] ||= 'development'
####################################################################################
require 'rack/jsonr'
require 'fanforce/api'
require 'fanforce/worker'
require 'active_support/all'
require 'sinatra/base'
require 'fileutils'
require 'redis'
require_relative 'app_factory/version'

if ENV['RACK_ENV'] == 'development'
  require_relative 'app_factory/sprockets/hacks'
  require_relative 'app_factory/sprockets/compiler'
end

caller[0].split(':')[0] =~ /^(.+(config\.ru|Rakefile))$/ ? ROOT_DIR = File.dirname($1) : nil

module FanforceApp

  def self.enqueue(queue_name, payload)
    Fanforce::Worker.enqueue "#{config._id}-#{queue_name}", payload
  end

  def self.config(&block)
    config = @@config ||= FanforceApp::CoreConfig.new(ROOT_DIR)
    if block.present?
      block.call(config)
      config.root_dir = File.dirname($1) if !config.root_dir and caller[0].split(':')[0] =~ /^(.+(config\.ru|Rakefile))$/
    end
    config
  end

  def self.root
    config.root_dir
  end

  def self.dir_name
    config.dir_name
  end

  def self._id
    config._id
  end

  def self.load_config
    config.load
  end

  def self.call(env)
    if ENV['RACK_ENV'] == 'development' and env['PATH_INFO'] =~ /^\/assets\//
      env['PATH_INFO'] = env['PATH_INFO'].gsub(/^\/assets/, '')
      sprockets = SprocketsCompiler.setup(FanforceApp.config.root_dir)
      return sprockets.index.call(env)
    end
    require_relative 'app_factory/_init_sinatra'
    request = Rack::Request.new(env)
    Rack::JSONR.intercept_method_override(env, request, request.params, :all)
    FanforceApp::Sinatra.new.call(env)
  end

  require_relative 'app_factory/config/core_config'
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fanforce-app-factory-0.40.1 lib/fanforce/app_factory.rb
fanforce-app-factory-0.40.0 lib/fanforce/app_factory.rb
fanforce-app-factory-0.39.1 lib/fanforce/app_factory.rb
fanforce-app-factory-0.39.0 lib/fanforce/app_factory.rb
fanforce-app-factory-0.38.2 lib/fanforce/app_factory.rb
fanforce-app-factory-0.38.1 lib/fanforce/app_factory.rb
fanforce-app-factory-0.38.0 lib/fanforce/app_factory.rb
fanforce-app-factory-0.37.1 lib/fanforce/app_factory.rb
fanforce-app-factory-0.37.0 lib/fanforce/app_factory.rb
fanforce-app-factory-0.36.0 lib/fanforce/app_factory.rb
fanforce-app-factory-0.35.1 lib/fanforce/app_factory.rb
fanforce-app-factory-0.34.2 lib/fanforce/app_factory.rb