Sha256: 9891ac5ccef451e36fe4189b67d79de9e518405e186cff1c329fc992637612b6

Contents?: true

Size: 878 Bytes

Versions: 4

Compression:

Stored size: 878 Bytes

Contents

require 'rack/cors'

module ForestLiana
  class Engine < ::Rails::Engine
    isolate_namespace ForestLiana

    config.middleware.insert_before 0, 'Rack::Cors' do
      allow do
        origins '*'
        resource '*', headers: :any, methods: :any
      end
    end

    unless Rails.env.test?
      config.after_initialize do
        SchemaUtils.tables_names.map do |table_name|
          model = SchemaUtils.find_model_from_table_name(table_name)
          SerializerFactory.new.serializer_for(model) if \
            model.try(:table_exists?)
        end

        # Monkey patch the find_serializer_class_name method to specify the good
        # serializer to use.
        JSONAPI::Serializer.class_eval do
          def self.find_serializer_class_name(obj)
            SerializerFactory.get_serializer_name(obj.class)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
forest_liana-1.0.7 lib/forest_liana/engine.rb
forest_liana-1.0.6 lib/forest_liana/engine.rb
forest_liana-1.0.5 lib/forest_liana/engine.rb
forest_liana-1.0.4 lib/forest_liana/engine.rb