Module: CaringForm::Dsl

Defined in:
lib/caring_form/dsl.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
10
# File 'lib/caring_form/dsl.rb', line 5

def self.included(klass)
  klass.instance_eval do
    include CaringForm::FieldContainer
    extend ClassMethods
  end
end

Instance Method Details

#attributes(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/caring_form/dsl.rb', line 27

def attributes(options = {})
  keys = if options.has_key?(:except)
           except = options[:except]
           field_names do |name, field|
             except.none? { |key, value| field[key] == value }
           end
         else
           field_names
         end
  keys.each_with_object({}) do |key, hash|
    next unless respond_to?(key)
    value = send(key)
    hash[key.to_sym] = value unless value.nil?
  end
end

#autofocus?(name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/caring_form/dsl.rb', line 12

def autofocus?(name)
  self.class.autofocus == name
end

#error_configObject



43
44
45
# File 'lib/caring_form/dsl.rb', line 43

def error_config
  self.class.error_config
end

#index_onObject



16
17
18
19
20
21
# File 'lib/caring_form/dsl.rb', line 16

def index_on
  return nil unless (index_name = self.class.index_on)
  return nil unless respond_to?(index_name)
  value = send(index_name)
  value.present? ? value : nil
end

#spam?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/caring_form/dsl.rb', line 23

def spam?
  self.class.can_check_spam? && reference.present?
end