提交 49d069d7 编写于 作者: C Carlos Antonio da Silva

Merge pull request #6904 from guilleiguaran/remove-amo-dependency-in-ap

Remove Active Model dependency from Action Pack
......@@ -18,7 +18,6 @@
s.requirements << 'none'
s.add_dependency('activesupport', version)
s.add_dependency('activemodel', version)
s.add_dependency('rack-cache', '~> 1.2')
s.add_dependency('builder', '~> 3.0.0')
s.add_dependency('rack', '~> 1.4.1')
......@@ -26,5 +25,6 @@
s.add_dependency('journey', '~> 1.0.1')
s.add_dependency('erubis', '~> 2.7.0')
s.add_development_dependency('activemodel', version)
s.add_development_dependency('tzinfo', '~> 0.3.33')
end
module ActionController
module ModelNaming
# Converts the given object to an ActiveModel compliant one.
def convert_to_model(object)
object.respond_to?(:to_model) ? object.to_model : object
end
def model_name_from_record_or_class(record_or_class)
(record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
end
end
end
require 'active_support/core_ext/module'
require 'action_controller/model_naming'
module ActionController
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
......@@ -27,6 +28,8 @@ module ActionController
module RecordIdentifier
extend self
include ModelNaming
JOIN = '_'.freeze
NEW = 'new'.freeze
......@@ -40,7 +43,7 @@ module RecordIdentifier
# dom_class(post, :edit) # => "edit_post"
# dom_class(Person, :edit) # => "edit_person"
def dom_class(record_or_class, prefix = nil)
singular = ActiveModel::Naming.param_key(record_or_class)
singular = model_name_from_record_or_class(record_or_class).param_key
prefix ? "#{prefix}#{JOIN}#{singular}" : singular
end
......@@ -73,8 +76,7 @@ def dom_id(record, prefix = nil)
# method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to
# make sure yourself that your dom ids are valid, in case you overwrite this method.
def record_key_for_dom_id(record)
record = record.to_model if record.respond_to?(:to_model)
key = record.to_key
key = convert_to_model(record).to_key
key ? key.join('_') : key
end
end
......
require 'action_controller/model_naming'
module ActionDispatch
module Routing
# Polymorphic URL helpers are methods for smart resolution to a named route call when
......@@ -53,6 +55,8 @@ module Routing
# form_for([blog, @post]) # => "/blog/posts/1"
#
module PolymorphicRoutes
include ActionController::ModelNaming
# Constructs a call to a named RESTful route for the given record and returns the
# resulting URL string. For example:
#
......@@ -154,10 +158,6 @@ def action_prefix(options)
options[:action] ? "#{options[:action]}_" : ''
end
def convert_to_model(object)
object.respond_to?(:to_model) ? object.to_model : object
end
def routing_type(options)
options[:routing_type] || :url
end
......@@ -169,7 +169,7 @@ def build_named_route_call(records, inflection, options = {})
if parent.is_a?(Symbol) || parent.is_a?(String)
parent
else
ActiveModel::Naming.singular_route_key(parent)
model_name_from_record_or_class(parent).singular_route_key
end
end
else
......@@ -181,9 +181,9 @@ def build_named_route_call(records, inflection, options = {})
route << record
elsif record
if inflection == :singular
route << ActiveModel::Naming.singular_route_key(record)
route << model_name_from_record_or_class(record).singular_route_key
else
route << ActiveModel::Naming.route_key(record)
route << model_name_from_record_or_class(record).route_key
end
else
raise ArgumentError, "Nil location provided. Can't build URI."
......
......@@ -12,6 +12,7 @@
require 'active_support/core_ext/array/extract_options'
require 'active_support/deprecation'
require 'active_support/core_ext/string/inflections'
require 'action_controller/model_naming'
module ActionView
# = Action View Form Helpers
......@@ -117,11 +118,7 @@ module FormHelper
include FormTagHelper
include UrlHelper
# Converts the given object to an ActiveModel compliant one.
def convert_to_model(object)
object.respond_to?(:to_model) ? object.to_model : object
end
include ActionController::ModelNaming
# Creates a form that allows the user to create or update the attributes
# of a specific model object.
......@@ -411,7 +408,7 @@ def form_for(record, options = {}, &proc)
object = nil
else
object = record.is_a?(Array) ? record.last : record
object_name = options[:as] || ActiveModel::Naming.param_key(object)
object_name = options[:as] || model_name_from_record_or_class(object).param_key
apply_form_for_options!(record, object, options)
end
......@@ -1128,7 +1125,7 @@ def instantiate_builder(record_name, record_object, options)
object_name = record_name
else
object = record_name
object_name = ActiveModel::Naming.param_key(object)
object_name = model_name_from_record_or_class(object).param_key
end
builder = options[:builder] || default_form_builder
......@@ -1142,9 +1139,11 @@ def default_form_builder
end
class FormBuilder
include ActionController::ModelNaming
# The methods which wrap a form helper call.
class_attribute :field_helpers
self.field_helpers = FormHelper.instance_methods - [:form_for, :convert_to_model]
self.field_helpers = FormHelper.instance_methods - [:form_for, :convert_to_model, :model_name_from_record_or_class]
attr_accessor :object_name, :object, :options
......@@ -1214,7 +1213,7 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
end
else
record_object = record_name.is_a?(Array) ? record_name.last : record_name
record_name = ActiveModel::Naming.param_key(record_object)
record_name = model_name_from_record_or_class(record_object).param_key
end
index = if options.has_key?(:index)
......@@ -1396,10 +1395,6 @@ def nested_child_index(name)
@nested_child_index[name] ||= -1
@nested_child_index[name] += 1
end
def convert_to_model(object)
object.respond_to?(:to_model) ? object.to_model : object
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册