Class: NotNaughty::Builder::ValidationDelegator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/not_naughty/builder.rb

Overview

:nodoc:all

Instance Method Summary collapse

Constructor Details

#initialize(receiver, *params) ⇒ ValidationDelegator

Returns a new instance of ValidationDelegator.



42
43
44
45
46
47
# File 'lib/not_naughty/builder.rb', line 42

def initialize(receiver, *params)
  @_sd_obj_opts   = params.extract_options!
  @_sd_obj_params = params
  
  super receiver
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *params) ⇒ Object

:nodoc:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/not_naughty/builder.rb', line 48

def method_missing(method_sym, *params) #:nodoc:
  method_sym, params = unless @_sd_obj_params.empty?
    opts = @_sd_obj_opts.update params.extract_options!
    [:"validates_#{method_sym}_of", @_sd_obj_params + [opts]]
  else
    opts = @_sd_obj_opts.update params.extract_options!
    [:"validates_#{method_sym}", params + [opts]]
  end
  
  if @_sd_obj.respond_to? method_sym
    @_sd_obj.send!(method_sym, *params)
    return true
  else
    raise NoMethodError,
      "unable to evaluate ยด#{method_sym}(*#{params.inspect})'"
  end
end