@@ -135,7 +135,7 @@ module ClassMethods
135
135
# expected API. It is recommended that your type objects inherit from an
136
136
# existing type, or from ActiveRecord::Type::Value
137
137
#
138
- # class MoneyType < ActiveRecord::Type::Integer
138
+ # class PriceType < ActiveRecord::Type::Integer
139
139
# def cast(value)
140
140
# if !value.kind_of?(Numeric) && value.include?('$')
141
141
# price_in_dollars = value.gsub(/\$/, '').to_f
@@ -147,11 +147,11 @@ module ClassMethods
147
147
# end
148
148
#
149
149
# # config/initializers/types.rb
150
- # ActiveRecord::Type.register(:money, MoneyType )
150
+ # ActiveRecord::Type.register(:price, PriceType )
151
151
#
152
152
# # app/models/store_listing.rb
153
153
# class StoreListing < ActiveRecord::Base
154
- # attribute :price_in_cents, :money
154
+ # attribute :price_in_cents, :price
155
155
# end
156
156
#
157
157
# store_listing = StoreListing.new(price_in_cents: '$10.00')
@@ -171,7 +171,7 @@ module ClassMethods
171
171
# class Money < Struct.new(:amount, :currency)
172
172
# end
173
173
#
174
- # class MoneyType < ActiveRecord::Type::Value
174
+ # class PriceType < ActiveRecord::Type::Value
175
175
# def initialize(currency_converter:)
176
176
# @currency_converter = currency_converter
177
177
# end
@@ -186,12 +186,12 @@ module ClassMethods
186
186
# end
187
187
#
188
188
# # config/initializers/types.rb
189
- # ActiveRecord::Type.register(:money, MoneyType )
189
+ # ActiveRecord::Type.register(:price, PriceType )
190
190
#
191
191
# # app/models/product.rb
192
192
# class Product < ActiveRecord::Base
193
193
# currency_converter = ConversionRatesFromTheInternet.new
194
- # attribute :price_in_bitcoins, :money , currency_converter: currency_converter
194
+ # attribute :price_in_bitcoins, :price , currency_converter: currency_converter
195
195
# end
196
196
#
197
197
# Product.where(price_in_bitcoins: Money.new(5, "USD"))
0 commit comments