1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rename property to attribute

For consistency with https://github.com/rails/rails/pull/15557
This commit is contained in:
Sean Griffin 2014-06-07 07:09:45 -06:00
parent 23a751c2e1
commit 3fab9d8821
8 changed files with 26 additions and 26 deletions

View file

@ -62,7 +62,7 @@ module ActiveRecord
if type.serialized?
type = type.subtype
end
property attr_name, Type::Serialized.new(type, coder)
attribute attr_name, Type::Serialized.new(type, coder)
# merge new serialized attribute and create new hash to ensure that each class in inheritance hierarchy
# has its own hash of own serialized attributes

View file

@ -1,5 +1,5 @@
module ActiveRecord
module Properties # :nodoc:
module Attributes # :nodoc:
extend ActiveSupport::Concern
Type = ActiveRecord::Type
@ -10,7 +10,7 @@ module ActiveRecord
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 ActiveRecord
# 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 ActiveRecord
# 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 ActiveRecord
# 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

View file

@ -19,7 +19,7 @@ require 'active_record/errors'
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
@ -322,7 +322,7 @@ module ActiveRecord #:nodoc:
include Reflection
include Serialization
include Store
include Properties
include Attributes
end
ActiveSupport.run_load_hooks(:active_record, Base)

View file

@ -1,17 +1,17 @@
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 @@ module ActiveRecord
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 @@ module ActiveRecord
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')

View file

@ -985,9 +985,9 @@ class BasicsTest < ActiveRecord::TestCase
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

View file

@ -16,9 +16,9 @@ Company.has_many :accounts
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

View file

@ -631,7 +631,7 @@ class DirtyTest < ActiveRecord::TestCase
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

View file

@ -13,10 +13,10 @@ require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers"
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