Sha256: ac041e9862effaca2ce29970d71e502106aace1d4c39759edcf2ba843ef9d15c

Contents?: true

Size: 637 Bytes

Versions: 2

Compression:

Stored size: 637 Bytes

Contents

# frozen_string_literal: true

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

2 entries across 2 versions & 1 rubygems

Version Path
alba-3.3.1 lib/alba/railtie.rb
alba-3.3.0 lib/alba/railtie.rb