Sha256: 5ef46b9d1c763b4d8eb67e53d5eb8632d393bc4dbcaed89d5ea386cabecf5ca9

Contents?: true

Size: 815 Bytes

Versions: 5

Compression:

Stored size: 815 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

    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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
forest_liana-1.0.3 lib/forest_liana/engine.rb
forest_liana-1.0.2 lib/forest_liana/engine.rb
forest_liana-1.0.1 lib/forest_liana/engine.rb
forest_liana-1.0.0.beta7 lib/forest_liana/engine.rb
forest_liana-1.0.0.beta6 lib/forest_liana/engine.rb