Sha256: f36a51af2b634fb9d4ee1acf590d7b23da730c0554923d3acca1392c667816d4

Contents?: true

Size: 860 Bytes

Versions: 2

Compression:

Stored size: 860 Bytes

Contents

module MagicLamp
  class FixturesController < ApplicationController
    ERRORS = [
      "MagicLamp::ArgumentError",
      "MagicLamp::AlreadyRegisteredFixtureError",
      "MagicLamp::AmbiguousFixtureNameError",
      "MagicLamp::UnregisteredFixtureError"
    ]

    rescue_from(*ERRORS) do |exception, message = exception.message|
      error_message_with_bactrace = parse_error(exception, message)
      logger.error(error_message_with_bactrace)
      render text: message, status: 400
    end

    def show
      namespace.load_lamp_files
      render text: namespace.generate_fixture(params[:name])
    end

    def index
      render json: namespace.generate_all_fixtures
    end

    private

    def parse_error(exception, message)
      ([message] + exception.backtrace).join("\n\s\s\s\s")
    end

    def namespace
      MagicLamp
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
magic_lamp-1.1.0 app/controllers/magic_lamp/fixtures_controller.rb
magic_lamp-1.0.0 app/controllers/magic_lamp/fixtures_controller.rb