Sha256: 896298e82e70ea2af9cdc96cb1615065caf9e2776f2d73e1d682aa3849a6b539

Contents?: true

Size: 606 Bytes

Versions: 1

Compression:

Stored size: 606 Bytes

Contents

module Alba
  # Rails integration
  class Railtie < Rails::Railtie
    initializer 'alba.initialize' do
      Alba.inflector = :active_support

      ActiveSupport.on_load(:action_controller) do
        ActionController::Base.define_method(:serialize) do |obj, with: nil, &block|
          with.nil? ? Alba.resource_with(obj, &block) : with.new(obj)
        end

        ActionController::Base.define_method(:render_serialized_json) do |obj, with: nil, &block|
          json = with.nil? ? Alba.resource_with(obj, &block) : with.new(obj)
          render json: json
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alba-3.2.0 lib/alba/railtie.rb