Sha256: 4ca3040f65138f8ea2321519072daf24520e4e9d198969dcb85959ea484e668d
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
module Valle class Hooks class << self ## # Runs all the hooks, required for this gem # def init ActiveSupport.on_load(:active_record) do Valle::Hooks.extend_inherited_method if Valle.enabled? end end ## # Extends the functionality of inherited method # def extend_inherited_method ActiveRecord::Base.class_eval do class << self def inherited_with_valle_validators(subclass) inherited_without_valle_validators(subclass) if (Valle.can_process_model?(subclass.model_name) && self == ActiveRecord::Base && subclass != ActiveRecord::SchemaMigration) Valle::Hooks.extend_ar_validations_valid_method(subclass) end end alias_method_chain :inherited, :valle_validators end end end ## # Extends the functionality of ActiveRecord::Validations valid? method # # @param [ActiveRecord::Base] subclass the AR::Base child class # @note ActiveRecord::Validations should be defined at this point # def extend_ar_validations_valid_method(subclass) Valle::Manager.add_validators(subclass) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
valle-0.2.0 | lib/valle/hooks.rb |
valle-0.1.0 | lib/valle/hooks.rb |