module ObjectAttorney::ClassMethods
Attributes
allegations[W]
defendant_options[W]
Public Instance Methods
allegations()
click to toggle source
# File lib/object_attorney/class_methods.rb, line 15 def allegations @allegations ||= Hash.new { |hash, key| hash[key] = [] } end
defend(name, options = {})
click to toggle source
# File lib/object_attorney/class_methods.rb, line 11 def defend(name, options = {}) defendant_options.merge!(options.merge(name: name)) end
defendant_options()
click to toggle source
# File lib/object_attorney/class_methods.rb, line 7 def defendant_options @defendant_options ||= {} end
inherited(base)
click to toggle source
Copy allegations on inheritance.
Calls superclass method
# File lib/object_attorney/class_methods.rb, line 39 def inherited(base) base.allegations = allegations.clone base.defendant_options = defendant_options.clone super end
validate(*args, &block)
click to toggle source
# File lib/object_attorney/class_methods.rb, line 19 def validate(*args, &block) allegations[nil] << Allegation.new(:custom, args, &block) end
validates_with(*args, &block)
click to toggle source
# File lib/object_attorney/class_methods.rb, line 23 def validates_with(*args, &block) options = args.extract_options! # certain ActiveModel::Validations::<Class> need this options[:class] = self args.each do |validation_class| allegation = Allegation.new(validation_class, options, &block) allegation.attributes.each do |attribute| allegations[attribute.to_sym].push allegation end end end