mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Remove Rails dependency
Move configuration into a Railtie. Only dependency is now activemodel
This commit is contained in:
parent
ed3c510d2e
commit
fffce85c5d
@ -12,6 +12,8 @@ Gem::Specification.new do |gem|
|
|||||||
gem.name = "active_model_serializers"
|
gem.name = "active_model_serializers"
|
||||||
gem.require_paths = ["lib"]
|
gem.require_paths = ["lib"]
|
||||||
gem.version = "0.0.1"
|
gem.version = "0.0.1"
|
||||||
|
|
||||||
gem.add_dependency "rails", "~> 3.0"
|
gem.add_dependency 'activemodel', '~> 3.0'
|
||||||
|
|
||||||
|
gem.add_development_dependency "rails", "~> 3.0"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,7 +16,7 @@ module ActionController
|
|||||||
#
|
#
|
||||||
# class ApplicationController < ActionController::Base
|
# class ApplicationController < ActionController::Base
|
||||||
# private
|
# private
|
||||||
#
|
#
|
||||||
# def serialization_scope
|
# def serialization_scope
|
||||||
# current_user
|
# current_user
|
||||||
# end
|
# end
|
||||||
@ -48,4 +48,4 @@ module ActionController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -23,12 +23,10 @@ ActiveModel::Serialization.class_eval do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "action_controller"
|
begin
|
||||||
|
require 'action_controller'
|
||||||
module ActionController
|
require 'rails'
|
||||||
autoload :Serialization, "action_controller/serialization"
|
require 'railtie'
|
||||||
|
rescue LoadError => ex
|
||||||
|
# rails on installed, continuing
|
||||||
end
|
end
|
||||||
|
|
||||||
ActiveSupport.on_load(:action_controller) do
|
|
||||||
include ::ActionController::Serialization
|
|
||||||
end
|
|
||||||
14
lib/railtie.rb
Normal file
14
lib/railtie.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require 'active_model_serializers'
|
||||||
|
require 'action_controller/serialization'
|
||||||
|
|
||||||
|
module ActiveModel
|
||||||
|
module Serialization
|
||||||
|
class Railtie < ::Rails::Railtie
|
||||||
|
initializer "active_model.serialization.action_controller" do
|
||||||
|
ActiveSupport.on_load(:action_controller) do
|
||||||
|
include ::ActionController::Serilization
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,4 +1,4 @@
|
|||||||
require 'rails'
|
require 'test_helper'
|
||||||
|
|
||||||
class Foo < Rails::Application
|
class Foo < Rails::Application
|
||||||
end
|
end
|
||||||
|
|||||||
@ -39,6 +39,8 @@ class RenderJsonTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestController < ActionController::Base
|
class TestController < ActionController::Base
|
||||||
|
include ActionController::Serialization
|
||||||
|
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
|
|
||||||
serialization_scope :current_user
|
serialization_scope :current_user
|
||||||
@ -169,4 +171,4 @@ class RenderJsonTest < ActionController::TestCase
|
|||||||
get :render_json_with_serializer_api_but_without_serializer
|
get :render_json_with_serializer_api_but_without_serializer
|
||||||
assert_match '{"serializable_object":true}', @response.body
|
assert_match '{"serializable_object":true}', @response.body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,4 +21,4 @@ ActiveSupport::TestCase.class_eval do
|
|||||||
setup do
|
setup do
|
||||||
@routes = ::TestHelper::Routes
|
@routes = ::TestHelper::Routes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user