Sha256: 98b5864f6ff1b34fc72ff72632a7b998f8cde28c7e2e244465166257c776ead0

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

module JsTestServer
  class Configuration
    class << self
      attr_accessor :instance

      def method_missing(method_name, *args, &block)
        if Configuration.instance.respond_to?(method_name)
          Configuration.instance.send(method_name, *args, &block)
        else
          super
        end
      end
    end

    attr_reader :host, :port, :spec_path, :root_path, :framework_path, :framework_name
    attr_writer :host, :port, :framework_path, :framework_name

    def initialize(params={})
      params = Server::DEFAULTS.dup.merge(params)
      @spec_path = ::File.expand_path(params[:spec_path])
      @root_path = ::File.expand_path(params[:root_path])
      @host = params[:host]
      @port = params[:port]
      @framework_path = params[:framework_path]
      @framework_name = params[:framework_name]
    end

    def suite_representation_class
      if framework_name
        JsTestServer::Server::Representations::Suites.const_get(framework_name.gsub("-", "_").camelcase)
      end
    end

    def spec_path=(path)
      validate_path(path)
      @spec_path = path
    end

    def root_path=(path)
      validate_path(path)
      @root_path = path
    end

    def js_test_server_root_path
      "#{library_root_dir}/public"
    end

    def root_url
      "http://#{host}:#{port}"
    end

    def rackup_path
      File.expand_path("#{File.dirname(__FILE__)}/server/standalone.ru")
    end

    protected

    def library_root_dir
      dir = File.dirname(__FILE__)
      File.expand_path("#{dir}/../..")
    end

    def validate_path(path)
      unless File.directory?(path)
        raise ArgumentError, "#{path} must be a directory"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
js-test-server-0.2.1 lib/js_test_server/configuration.rb
js-test-server-0.2.0 lib/js_test_server/configuration.rb