Module: Ciesta::ClassMethods

Extended by:
ClassMethods
Included in:
ClassMethods
Defined in:
lib/ciesta/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#definitionsCiesta::FieldList

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns fields definitions

Returns:



31
32
33
# File 'lib/ciesta/class_methods.rb', line 31

def definitions
  @definitions ||= {}
end

#field(name, **options) ⇒ Object

Declare new form field

Parameters:

  • name (Symbol)

    Field name

  • options (Hash)

    Options



10
11
12
13
14
15
16
17
# File 'lib/ciesta/class_methods.rb', line 10

def field(name, **options)
  name = name.to_sym
  definitions[name] = options
  proxy.instance_eval do
    define_method(name) { fields[name] }
    define_method("#{name}=") { |value| fields[name] = value }
  end
end

#proxyObject



43
44
45
46
47
48
49
# File 'lib/ciesta/class_methods.rb', line 43

def proxy
  @proxy ||= begin
    m = Module.new
    include m
    m
  end
end

#validate(&block) ⇒ Object

Declare rules for validation

Parameters:

  • block (Block)

    Block with validation rules

See Also:



23
24
25
# File 'lib/ciesta/class_methods.rb', line 23

def validate(&block)
  validator.use(&block)
end

#validatorCiesta::Validator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns form validator

Returns:



39
40
41
# File 'lib/ciesta/class_methods.rb', line 39

def validator
  @validator ||= Ciesta::Validator.new
end