Class: DataMapper::Form::Elements::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-forms/elements.rb

Overview

Proxy object for capturing elements. See Elements#capture_elements.

Instance Method Summary collapse

Constructor Details

#initialize(model = nil) ⇒ Proxy

Returns a new instance of Proxy.



10
11
12
# File 'lib/dm-forms/elements.rb', line 10

def initialize model = nil
  @model = model 
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



14
15
16
17
# File 'lib/dm-forms/elements.rb', line 14

def method_missing meth, *args, &block
  add_error_class_to args if has_a_model_with_errors_on? args.first
  (@elements ||= []) << Elements.send(meth, *args, &block)
end

Instance Method Details

#add_error_class_to(args) ⇒ Object



19
20
21
# File 'lib/dm-forms/elements.rb', line 19

def add_error_class_to args
  ((args[1] ||= {})[:class] ||= '') << ' error'
end

#has_a_model_with_errors_on?(meth) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dm-forms/elements.rb', line 23

def has_a_model_with_errors_on? meth
  @model and !@model.valid? and @model.errors.on meth
end