提交 cf94a551 编写于 作者: R Rafael Mendonça França

Merge pull request #15558 from sgrif/sg-rename-property

Rename `property` to `attribute`

Conflicts:
	activerecord/lib/active_record/attribute_methods/serialization.rb
	activerecord/lib/active_record/base.rb
module ActiveRecord
module Properties # :nodoc:
module Attributes # :nodoc:
extend ActiveSupport::Concern
Type = ActiveRecord::Type
......@@ -10,7 +10,7 @@ module Properties # :nodoc:
end
module ClassMethods
# Defines or overrides a property on this model. This allows customization of
# Defines or overrides a attribute on this model. This allows customization of
# Active Record's type casting behavior, as well as adding support for user defined
# types.
#
......@@ -44,7 +44,7 @@ module ClassMethods
# store_listing.price_in_cents # => BigDecimal.new(10.1)
#
# class StoreListing < ActiveRecord::Base
# property :price_in_cents, Type::Integer.new
# attribute :price_in_cents, Type::Integer.new
# end
#
# # after
......@@ -53,7 +53,7 @@ module ClassMethods
# Users may also define their own custom types, as long as they respond to the methods
# defined on the value type. The `type_cast` method on your type object will be called
# with values both from the database, and from your controllers. See
# `ActiveRecord::Properties::Type::Value` for the expected API. It is recommended that your
# `ActiveRecord::Attributes::Type::Value` for the expected API. It is recommended that your
# type objects inherit from an existing type, or the base value type.
#
# class MoneyType < ActiveRecord::Type::Integer
......@@ -68,12 +68,12 @@ module ClassMethods
# end
#
# class StoreListing < ActiveRecord::Base
# property :price_in_cents, MoneyType.new
# attribute :price_in_cents, MoneyType.new
# end
#
# store_listing = StoreListing.new(price_in_cents: '$10.00')
# store_listing.price_in_cents # => 1000
def property(name, cast_type, options = {})
def attribute(name, cast_type, options = {})
name = name.to_s
clear_caches_calculated_from_columns
# Assign a new hash to ensure that subclasses do not share a hash
......
......@@ -20,7 +20,7 @@
require 'active_record/log_subscriber'
require 'active_record/explain_subscriber'
require 'active_record/relation/delegation'
require 'active_record/properties'
require 'active_record/attributes'
module ActiveRecord #:nodoc:
# = Active Record
......@@ -323,7 +323,7 @@ class Base
include Reflection
include Serialization
include Store
include Properties
include Attributes
include AttributeDecorators
end
......
require 'cases/helper'
class OverloadedType < ActiveRecord::Base
property :overloaded_float, Type::Integer.new
property :overloaded_string_with_limit, Type::String.new(limit: 50)
property :non_existent_decimal, Type::Decimal.new
property :string_with_default, Type::String.new, default: 'the overloaded default'
attribute :overloaded_float, Type::Integer.new
attribute :overloaded_string_with_limit, Type::String.new(limit: 50)
attribute :non_existent_decimal, Type::Decimal.new
attribute :string_with_default, Type::String.new, default: 'the overloaded default'
end
class ChildOfOverloadedType < OverloadedType
end
class GrandchildOfOverloadedType < ChildOfOverloadedType
property :overloaded_float, Type::Float.new
attribute :overloaded_float, Type::Float.new
end
class UnoverloadedType < ActiveRecord::Base
......@@ -54,7 +54,7 @@ def test_overloaded_properties_with_limit
assert_equal 255, UnoverloadedType.columns_hash['overloaded_string_with_limit'].limit
end
def test_nonexistent_property
def test_nonexistent_attribute
data = OverloadedType.new(non_existent_decimal: 1)
assert_equal BigDecimal.new(1), data.non_existent_decimal
......@@ -98,7 +98,7 @@ def test_caches_are_cleared
assert_not klass.column_names.include?('wibble')
assert_equal 5, klass.content_columns.length
klass.property :wibble, Type::Value.new
klass.attribute :wibble, Type::Value.new
assert_equal 7, klass.columns.length
assert klass.columns_hash.key?('wibble')
......
......@@ -985,9 +985,9 @@ def test_geometric_content
class NumericData < ActiveRecord::Base
self.table_name = 'numeric_data'
property :world_population, Type::Integer.new
property :my_house_population, Type::Integer.new
property :atoms_in_universe, Type::Integer.new
attribute :world_population, Type::Integer.new
attribute :my_house_population, Type::Integer.new
attribute :atoms_in_universe, Type::Integer.new
end
def test_big_decimal_conditions
......
......@@ -16,9 +16,9 @@
class NumericData < ActiveRecord::Base
self.table_name = 'numeric_data'
property :world_population, Type::Integer.new
property :my_house_population, Type::Integer.new
property :atoms_in_universe, Type::Integer.new
attribute :world_population, Type::Integer.new
attribute :my_house_population, Type::Integer.new
attribute :atoms_in_universe, Type::Integer.new
end
class CalculationsTest < ActiveRecord::TestCase
......
......@@ -631,7 +631,7 @@ def type_cast_for_write(value)
model_class = Class.new(ActiveRecord::Base) do
self.table_name = 'numeric_data'
property :foo, type.new, default: 1
attribute :foo, type.new, default: 1
end
model = model_class.new
......
......@@ -13,10 +13,10 @@
class BigNumber < ActiveRecord::Base
unless current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter)
property :value_of_e, Type::Integer.new
attribute :value_of_e, Type::Integer.new
end
property :world_population, Type::Integer.new
property :my_house_population, Type::Integer.new
attribute :world_population, Type::Integer.new
attribute :my_house_population, Type::Integer.new
end
class Reminder < ActiveRecord::Base; end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册