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



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

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

Instance Method Details

#target(target_name) ⇒ Object



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

def target(target_name)
  @target_name = target_name
end

#target_nameObject



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

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

#trial_courtObject



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

def trial_court
  @trial_court ||= Trial::Court.new \
    Judge::Base, DefenseAttorney::Base, Validator, Context::Base
end

#validate(*args, &block) ⇒ Object



26
27
28
# File 'lib/rest_my_case/validator.rb', line 26

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

#validates_with(*args, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rest_my_case/validator.rb', line 30

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