Module: RestMyCase::Validator::ClassMethods

Included in:
RestMyCase::Validator
Defined in:
lib/rest_my_case/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#validatorsObject



18
19
20
# File 'lib/rest_my_case/validator.rb', line 18

def validators
  @validators ||= Hash.new { |hash, key| hash[key] = [] }
end

Instance Method Details

#target(target_name, target_options = {}) ⇒ Object



13
14
15
16
# File 'lib/rest_my_case/validator.rb', line 13

def target(target_name, target_options = {})
  @target_options = target_options || {}
  @target_options[:name] = target_name
end

#target_optionsObject



9
10
11
# File 'lib/rest_my_case/validator.rb', line 9

def target_options
  @target_options || Helpers.super_method(self, :target_options)
end

#validate(*args, &block) ⇒ Object



22
23
24
# File 'lib/rest_my_case/validator.rb', line 22

def validate(*args, &block)
  validators[nil] << AccusationAttorneys::Custom.new(args, &block)
end

#validates_with(*args, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/rest_my_case/validator.rb', line 26

def validates_with(*args, &block)
  options = Helpers.extract_options!(args)

  options[:class] = self

  args.each do |klass|
    store_validators_by_attribute klass.new(options, &block)
  end
end