Sha256: 2eccc4b632be4ef990b627bd177d6df6411622a2724ce9edb3ac4c49d9c45215

Contents?: true

Size: 1.97 KB

Versions: 5

Compression:

Stored size: 1.97 KB

Contents

require 'redis'
require 'fileutils'
require 'rack/jsonr'
require 'rack/jquery-params'
require 'rack/cors'
require 'sinatra/base'
require 'active_support/all'
require 'fanforce/api'
require 'fanforce/plugin_worker'

class Fanforce::Plugin
  require_relative 'core_config'

  @@loaded = nil
  @@config = nil

  # Only one instance is allowed to initialize, and the resulting instance is stored in Fanforce::Plugin.
  # @param base_dir [String] base dir of plugin
  # @param loader_filename [String] either config.ru or Rakefile
  # @return [Fanforce::Plugin]
  def self.load(base_dir)
    @@loaded ? (raise 'Only one instance of Fanforce::PluginFactory can be loaded per process') : @@loaded = true
    @@config = CoreConfig.new(base_dir)
    return self
  end

  def self.plugin_id
    @@config._id
  end
  def self._id; plugin_id; end

  def self.config(&block)
    block ? block.call(@@config) : @@config
  end

  def self.base_dir
    @@config.base_dir
  end

  def self.is_bugsnag_enabled?
    @@config.is_bugsnag_enabled
  end

  def self.redis
    @@redis ||= ::Redis.new(url: @@config.redis_url)
  end

  ######################################################################################################################

  # Method for use in config.ru files (i.e., run Fanforce::Plugin)
  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(base_dir)
      return sprockets.index.call(env)
    end
    return Rack::File.new("#{base_dir}").call(env) if env['PATH_INFO'] =~ /^\/(favicon.ico|robots.txt)/

    require_relative 'sinatra/_load'
    request = Rack::Request.new(env)
    Sass::Plugin.options[:cache_location] = './tmp/sass-cache'
    sass_options = {:cache_location => "path\to\tmp\sass-cache"}
    Rack::JSONR.intercept_method_override(env, request, request.params, :all)
    Rack::JQueryParams.fix(env, :all)
    Sinatra.new.call(env)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fanforce-plugin-factory-2.0.0.rc6 lib/fanforce/plugin_factory/plugin.rb
fanforce-plugin-factory-2.0.0.rc5 lib/fanforce/plugin_factory/plugin.rb
fanforce-plugin-factory-2.0.0.rc3 lib/fanforce/plugin_factory/plugin.rb
fanforce-plugin-factory-2.0.0.rc2 lib/fanforce/plugin_factory/plugin.rb
fanforce-plugin-factory-2.0.0.rc1 lib/fanforce/plugin_factory/plugin.rb