Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Auto include macros in Mongoid. #20

Open
wants to merge 1 commit into from

1 participant

@hbakhtiyor

Now can to use validates_formatting_of or sexy validates style in Mongoid without including.
e.g

  class Address
    include Mongoid::Document

    field :email, type: String

    validates_formatting_of :email
    # or
    # validates :email, presence: true, email: true
  end
@hbakhtiyor hbakhtiyor Auto include macros in Mongoid.
Now can to use validates_formatting_of or sexy validates style in Mongoid without including.
e.g
```ruby
  class Address
    include Mongoid::Document

    field :email, type: String

    validates_formatting_of :email
    # or
    # validates :email, presence: true, email: true
  end
```
375e8d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 12, 2013
  1. @hbakhtiyor

    Auto include macros in Mongoid.

    hbakhtiyor authored
    Now can to use validates_formatting_of or sexy validates style in Mongoid without including.
    e.g
    ```ruby
      class Address
        include Mongoid::Document
    
        field :email, type: String
    
        validates_formatting_of :email
        # or
        # validates :email, presence: true, email: true
      end
    ```
This page is out of date. Refresh to see the latest.
View
8 lib/validates_formatting_of/railtie.rb
@@ -5,12 +5,20 @@ class Railtie < Rails::Railtie
ActiveSupport.on_load :active_record do
extend ModelAdditions
end
+
+ ActiveSupport.on_load :mongoid do
+ ::ClassMethods.send(:include, ModelAdditions)
+ end
end
initializer 'validates_formatting_of.validations' do
ActiveSupport.on_load :active_record do
include Validations
end
+
+ ActiveSupport.on_load :mongoid do
+ ActiveModel::Validations.send(:include, Validations)
+ end
end
end
end
View
2  validates_formatting_of.gemspec
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = ValidatesFormattingOf::VERSION
- gem.add_dependency "activemodel", "~> 3.0"
+ gem.add_dependency "activemodel", ">= 3.0"
gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
Something went wrong with that request. Please try again.