Class: Noodall::FormResponse

Inherits:
Object
  • Object
show all
Includes:
MongoMapper::Document
Defined in:
app/models/noodall/form_response.rb

Instance Method Summary collapse

Instance Method Details

#approve!Object



30
31
32
33
34
# File 'app/models/noodall/form_response.rb', line 30

def approve!
  self.approved = true
  self.save!
  self.class.defensio.put_document(defensio_signature, { :allow => true })
end

#initialize_from_database(attrs = {}) ⇒ Object

Overiden to set up keys after find



24
25
26
27
28
# File 'app/models/noodall/form_response.rb', line 24

def initialize_from_database(attrs={})
  super.tap do
    set_up_keys!
  end
end

#is_spam?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/noodall/form_response.rb', line 42

def is_spam?
  self.approved == false
end

#keysObject

Merge meta keys with real keys



57
58
59
# File 'app/models/noodall/form_response.rb', line 57

def keys
  super.merge( class_eval( 'keys' ) )
end

#mark_as_spam!Object



36
37
38
39
40
# File 'app/models/noodall/form_response.rb', line 36

def mark_as_spam!
  self.approved = false
  self.save!
  self.class.defensio.put_document(defensio_signature, { :allow => false })
end

#set_up_keys!Object

Create appropriate MongoMapper keys for current instance based on the fields of the form it belongs to



48
49
50
51
52
53
54
# File 'app/models/noodall/form_response.rb', line 48

def set_up_keys!
  form.fields.each do |f|
    class_eval do
      key f.underscored_name, f.keys['default'].type, :required => f.required, :default => f.default
    end
  end if form
end