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



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

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

Instance Method Details

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



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

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

#target_optionsObject



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

def target_options
  @target_options || Helpers.super_method(self, :target_options)
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



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

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

#validates_with(*args, &block) ⇒ Object



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

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