Sha256: 1ec982d3632ebfd6911b8e0a2f63f39f75ee32e9ba6d6a934054f1030845a4b9

Contents?: true

Size: 820 Bytes

Versions: 1

Compression:

Stored size: 820 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)
          "ForestLiana::#{obj.class.name.demodulize}Serializer"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forest_liana-1.0.0.beta5 lib/forest_liana/engine.rb