diff options
Diffstat (limited to 'activemodel/lib')
12 files changed, 35 insertions, 43 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 6510629248..6882b59e26 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -75,14 +75,14 @@ module ActiveModel @messages = {} end - def initialize_dup(other) #:nodoc: + def initialize_dup(other) # :nodoc: @messages = other.messages.dup super end # Clear the error messages. # - # person.errors.full_messages # => ["name can not be nil"] + # person.errors.full_messages # => ["name can not be nil"] # person.errors.clear # person.errors.full_messages # => [] def clear @@ -92,9 +92,9 @@ module ActiveModel # Returns +true+ if the error messages include an error for the given key # +attribute+, +false+ otherwise. # - # person.errors.messages # => { :name => ["can not be nil"] } + # person.errors.messages # => {:name=>["can not be nil"]} # person.errors.include?(:name) # => true - # person.errors.include?(:age) # => false + # person.errors.include?(:age) # => false def include?(attribute) (v = messages[attribute]) && v.any? end @@ -103,7 +103,7 @@ module ActiveModel # Get messages for +key+. # - # person.errors.messages # => { :name => ["can not be nil"] } + # person.errors.messages # => {:name=>["can not be nil"]} # person.errors.get(:name) # => ["can not be nil"] # person.errors.get(:age) # => nil def get(key) @@ -177,7 +177,7 @@ module ActiveModel # Returns all message values. # - # person.errors.messages # => { :name => ["can not be nil", "must be specified"] } + # person.errors.messages # => {:name=>["can not be nil", "must be specified"]} # person.errors.values # => [["can not be nil", "must be specified"]] def values messages.values @@ -185,7 +185,7 @@ module ActiveModel # Returns all message keys. # - # person.errors.messages # => { :name => ["can not be nil", "must be specified"] } + # person.errors.messages # => {:name=>["can not be nil", "must be specified"]} # person.errors.keys # => [:name] def keys messages.keys @@ -240,8 +240,8 @@ module ActiveModel # object. You can pass the <tt>:full_messages</tt> option. This determines # if the json object should contain full messages or not (false by default). # - # person.as_json # => { :name => ["can not be nil"] } - # person.as_json(full_messages: true) # => { :name => ["name can not be nil"] } + # person.as_json # => {:name=>["can not be nil"]} + # person.as_json(full_messages: true) # => {:name=>["name can not be nil"]} def as_json(options=nil) to_hash(options && options[:full_messages]) end @@ -249,8 +249,8 @@ module ActiveModel # Returns a Hash of attributes with their error messages. If +full_messages+ # is +true+, it will contain full messages (see +full_message+). # - # person.to_hash # => { :name => ["can not be nil"] } - # person.to_hash(true) # => { :name => ["name can not be nil"] } + # person.to_hash # => {:name=>["can not be nil"]} + # person.to_hash(true) # => {:name=>["name can not be nil"]} def to_hash(full_messages = false) if full_messages messages = {} @@ -273,7 +273,7 @@ module ActiveModel # # => ["is invalid", "must be implemented"] # # person.errors.messages - # # => { :name => ["must be implemented", "is invalid"] } + # # => {:name=>["must be implemented", "is invalid"]} # # If +message+ is a symbol, it will be translated using the appropriate # scope (see +generate_message+). @@ -286,9 +286,9 @@ module ActiveModel # <tt>:strict</tt> option can also be set to any other exception. # # person.errors.add(:name, nil, strict: true) - # # => ActiveModel::StrictValidationFailed: name is invalid + # # => ActiveModel::StrictValidationFailed: name is invalid # person.errors.add(:name, nil, strict: NameIsInvalid) - # # => NameIsInvalid: name is invalid + # # => NameIsInvalid: name is invalid # # person.errors.messages # => {} def add(attribute, message = nil, options = {}) @@ -306,7 +306,7 @@ module ActiveModel # # person.errors.add_on_empty(:name) # person.errors.messages - # # => { :name => ["can't be empty"] } + # # => {:name=>["can't be empty"]} def add_on_empty(attributes, options = {}) [attributes].flatten.each do |attribute| value = @base.send(:read_attribute_for_validation, attribute) @@ -320,7 +320,7 @@ module ActiveModel # # person.errors.add_on_blank(:name) # person.errors.messages - # # => { :name => ["can't be blank"] } + # # => {:name=>["can't be blank"]} def add_on_blank(attributes, options = {}) [attributes].flatten.each do |attribute| value = @base.send(:read_attribute_for_validation, attribute) diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 81b44f97e0..2524b8d065 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -33,7 +33,7 @@ module ActiveModel # person.first_name = 'zoolander' # person.valid? # => false # person.invalid? # => true - # person.errors.messages # => {:first_name=>["starts with z."]} + # person.errors.messages # => {first_name:["starts with z."]} # # Note that <tt>ActiveModel::Validations</tt> automatically adds an +errors+ # method to your instances initialized with a new <tt>ActiveModel::Errors</tt> @@ -165,8 +165,8 @@ module ActiveModel # Person.validators # # => [ # # #<MyValidator:0x007fbff403e808 @options={}>, - # # #<OtherValidator:0x007fbff403d930 @options={:on=>:create}>, - # # #<StrictValidator:0x007fbff3204a30 @options={:strict=>true}> + # # #<OtherValidator:0x007fbff403d930 @options={on: :create}>, + # # #<StrictValidator:0x007fbff3204a30 @options={strict:true}> # # ] def validators _validators.values.flatten.uniq @@ -186,7 +186,7 @@ module ActiveModel # Person.validators_on(:name) # # => [ # # #<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>, - # # #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={:in=>0..99}> + # # #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={in:0..99}> # # ] def validators_on(*attributes) attributes.flat_map do |attribute| @@ -234,7 +234,7 @@ module ActiveModel # # person = Person.new # person.valid? # => false - # person.errors # => #<ActiveModel::Errors:0x007fe603816640 @messages={:name=>["can't be blank"]}> + # person.errors # => #<ActiveModel::Errors:0x007fe603816640 @messages={name:["can't be blank"]}> def errors @errors ||= Errors.new(self) end diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index ec7ad4b048..0935ad0d2a 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -1,8 +1,7 @@ module ActiveModel - # == Active \Model Acceptance \Validator module Validations - class AcceptanceValidator < EachValidator #:nodoc: + class AcceptanceValidator < EachValidator # :nodoc: def initialize(options) super({ :allow_nil => true, :accept => "1" }.merge!(options)) end @@ -27,7 +26,7 @@ module ActiveModel # # class Person < ActiveRecord::Base # validates_acceptance_of :terms_of_service - # validates_acceptance_of :eula, message: "must be abided" + # validates_acceptance_of :eula, message: 'must be abided' # end # # If the database column does not exist, the +terms_of_service+ attribute diff --git a/activemodel/lib/active_model/validations/confirmation.rb b/activemodel/lib/active_model/validations/confirmation.rb index 4071589747..3a3abce364 100644 --- a/activemodel/lib/active_model/validations/confirmation.rb +++ b/activemodel/lib/active_model/validations/confirmation.rb @@ -1,8 +1,7 @@ module ActiveModel - # == Active \Model Confirmation \Validator module Validations - class ConfirmationValidator < EachValidator #:nodoc: + class ConfirmationValidator < EachValidator # :nodoc: def validate_each(record, attribute, value) if (confirmed = record.send("#{attribute}_confirmation")) && (value != confirmed) human_attribute_name = record.class.human_attribute_name(attribute) diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index 7a90750c49..b7f38e48f5 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -2,9 +2,8 @@ require "active_model/validations/clusivity" module ActiveModel - # == Active \Model Exclusion \Validator module Validations - class ExclusionValidator < EachValidator #:nodoc: + class ExclusionValidator < EachValidator # :nodoc: include Clusivity def validate_each(record, attribute, value) diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb index 80150229a0..9398b7e66e 100644 --- a/activemodel/lib/active_model/validations/format.rb +++ b/activemodel/lib/active_model/validations/format.rb @@ -1,8 +1,7 @@ module ActiveModel - # == Active Model Format Validator module Validations - class FormatValidator < EachValidator #:nodoc: + class FormatValidator < EachValidator # :nodoc: def validate_each(record, attribute, value) if options[:with] regexp = option_call(record, :with) diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb index a333a09976..5e45a04c2c 100644 --- a/activemodel/lib/active_model/validations/inclusion.rb +++ b/activemodel/lib/active_model/validations/inclusion.rb @@ -2,9 +2,8 @@ require "active_model/validations/clusivity" module ActiveModel - # == Active \Model Inclusion \Validator module Validations - class InclusionValidator < EachValidator #:nodoc: + class InclusionValidator < EachValidator # :nodoc: include Clusivity def validate_each(record, attribute, value) diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index ffd045a8fb..744c196d30 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -1,6 +1,5 @@ module ActiveModel - # == Active \Model Numericality \Validator module Validations class NumericalityValidator < EachValidator # :nodoc: CHECKS = { :greater_than => :>, :greater_than_or_equal_to => :>=, @@ -126,7 +125,7 @@ module ActiveModel # For example: # # class Person < ActiveRecord::Base - # validates_numericality_of :width, less_than: Proc.new { |person| person.height } + # validates_numericality_of :width, less_than: ->(person) { person.height } # validates_numericality_of :width, greater_than: :minimum_weight # end def validates_numericality_of(*attr_names) diff --git a/activemodel/lib/active_model/validations/presence.rb b/activemodel/lib/active_model/validations/presence.rb index 70247ee4c8..ae84c376b9 100644 --- a/activemodel/lib/active_model/validations/presence.rb +++ b/activemodel/lib/active_model/validations/presence.rb @@ -1,7 +1,6 @@ module ActiveModel - # == Active \Model Presence \Validator module Validations class PresenceValidator < EachValidator # :nodoc: def validate(record) diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb index 03046a543a..4651154934 100644 --- a/activemodel/lib/active_model/validations/validates.rb +++ b/activemodel/lib/active_model/validations/validates.rb @@ -1,7 +1,6 @@ require 'active_support/core_ext/hash/slice' module ActiveModel - # == Active Model validates method module Validations module ClassMethods # This method is a shortcut to all default validators and any custom @@ -129,15 +128,15 @@ module ActiveModel # the validation itself. # # class Person - # include ActiveModel::Validations + # include ActiveModel::Validations # # attr_accessor :name # validates! :name, presence: true # end # # person = Person.new - # person.name = '' - # person.valid? + # person.name = '' + # person.valid? # # => ActiveModel::StrictValidationFailed: Name can't be blank def validates!(*attributes) options = attributes.extract_options! @@ -149,11 +148,11 @@ module ActiveModel # When creating custom validators, it might be useful to be able to specify # additional default keys. This can be done by overwriting this method. - def _validates_default_keys #:nodoc: + def _validates_default_keys # :nodoc: [:if, :unless, :on, :allow_blank, :allow_nil , :strict] end - def _parse_validates_options(options) #:nodoc: + def _parse_validates_options(options) # :nodoc: case options when TrueClass {} diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 869591cd9e..2ae335d0f4 100644 --- a/activemodel/lib/active_model/validations/with.rb +++ b/activemodel/lib/active_model/validations/with.rb @@ -10,7 +10,7 @@ module ActiveModel end end - class WithValidator < EachValidator #:nodoc: + class WithValidator < EachValidator # :nodoc: def validate_each(record, attr, val) method_name = options[:with] diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 09da4cc93d..c795dc9dcd 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -76,7 +76,7 @@ module ActiveModel # include ActiveModel::Validations # attr_accessor :title # - # validates :title, :presence => true + # validates :title, presence: true # end # # Validator may also define a +setup+ instance method which will get called |