Skip to content

Commit

Permalink
Rename define_field_type --> field_type, define_field_option --> fiel…
Browse files Browse the repository at this point in the history
…d_option
  • Loading branch information
johnnyshields committed Jul 12, 2022
1 parent 8715a66 commit 19f1b40
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/reference/fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ You may optionally declare a mapping for the new field type in an initializer:
# in /config/initializers/mongoid_custom_fields.rb

Mongoid.configure do |config|
config.define_field_type :point, Point
config.field_type :point, Point
end


Expand Down Expand Up @@ -1022,7 +1022,7 @@ specifiying its handler function as a block:
# in /config/initializers/mongoid_custom_fields.rb

Mongoid.configure do |config|
config.define_field_option :required do |model, field, value|
config.field_option :required do |model, field, value|
model.validates_presence_of field.name if value
end
end
Expand Down
4 changes: 2 additions & 2 deletions docs/release-notes/mongoid-8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ Mongoid 8.0 adds the ability to define custom ``field :type`` Symbol values as f
# in /config/initializers/mongoid.rb

Mongoid.configure do |config|
config.define_field_type :point, Point
config.field_type :point, Point
end

Refer to the :ref:`docs <http://docs.mongodb.org/manual/reference/fields/#custom-field-types>` for details.
Expand All @@ -341,7 +341,7 @@ Mongoid 8.0 adds the ability to define custom ``field`` options as follows:
# in /config/initializers/mongoid.rb

Mongoid.configure do |config|
config.define_field_option :required do |model, field, value|
config.field_option :required do |model, field, value|
model.validates_presence_of field.name if value
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ en:
valid options for the field. These are currently: %{valid}. If you
meant to define a custom field option, please do so first as follows:\n\n
\_\_Mongoid.configure do |config|\n
\_\_\_\_config.define_field_option :%{option} do |model, field, value|\n
\_\_\_\_config.field_option :%{option} do |model, field, value|\n
\_\_\_\_\_\_# Your logic here...\n
\_\_\_\_end\n
\_\_end\n
Expand Down Expand Up @@ -602,7 +602,7 @@ en:
resolution: "Please provide a known type value for the field. If you
meant to define a custom field type, please do so first as follows:\n\n
\_\_Mongoid.configure do |config|\n
\_\_\_\_config.define_field_type %{type_inspection}, YourTypeClass
\_\_\_\_config.field_type %{type_inspection}, YourTypeClass
\_\_end\n
\_\_class %{klass}\n
\_\_\_\_include Mongoid::Document\n
Expand Down
8 changes: 4 additions & 4 deletions lib/mongoid/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ def running_with_passenger?
#
# @example
# Mongoid.configure do |config|
# config.define_field_type :point, Point
# config.field_type :point, Point
# end
#
# @param [ Symbol | String ] type_name The identifier of the
# defined type. This identifier may be accessible as either a
# Symbol or a String regardless of the type passed to this method.
# @param [ Module ] klass the class of the defined type, which must
# include mongoize, demongoize, and evolve methods.
def define_field_type(type_name, klass)
def field_type(type_name, klass)
Mongoid::Fields::FieldTypes.define_type(type_name, klass)
end

Expand All @@ -339,15 +339,15 @@ def define_field_type(type_name, klass)
#
# @example
# Mongoid.configure do |config|
# config.define_field_option :required do |model, field, value|
# config.field_option :required do |model, field, value|
# model.validates_presence_of field.name if value
# end
# end
#
# @param [ Symbol ] option_name the option name to match against
# @param [ Proc ] block the handler to execute when the option is
# provided.
def define_field_option(option_name, &block)
def field_option(option_name, &block)
Mongoid::Fields.option(option_name, &block)
end

Expand Down
10 changes: 5 additions & 5 deletions spec/mongoid/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def self.logger
end
end

context '#define_field_type' do
context '#field_type' do
around do |example|
klass = Mongoid::Fields::FieldTypes
klass.instance_variable_set(:@mapping, klass::DEFAULT_MAPPING.dup)
Expand All @@ -825,29 +825,29 @@ def self.logger

it 'can define a custom type' do
Mongoid.configure do |config|
config.define_field_type :my_type, Integer
config.field_type :my_type, Integer
end

expect(Mongoid::Fields::FieldTypes.get(:my_type)).to eq Integer
end

it 'can override and existing type' do
Mongoid.configure do |config|
config.define_field_type :integer, String
config.field_type :integer, String
end

expect(Mongoid::Fields::FieldTypes.get(:integer)).to eq String
end
end

context '#define_field_option method' do
context '#field_option method' do
after do
Mongoid::Fields.instance_variable_set(:@options, {})
end

it 'can define a custom field option' do
Mongoid.configure do |config|
config.define_field_option :my_required do |model, field, value|
config.field_option :my_required do |model, field, value|
model.validates_presence_of field.name if value
end
end
Expand Down

0 comments on commit 19f1b40

Please sign in to comment.