Class: WPDB::GravityForms::ModelGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-wpdb/gravityforms.rb

Overview

For each form that we have, define a class for accessing its leads. So, if you have a form called “User Registration”, we’ll define a class called UserRegistration, allowing you to do things like:

WPDB::GravityForms::UserRegistration.where(:date_registered => ‘2013-01-01’).each do { |l| puts “#ll.first_name #ll.last_name” }

All fields in the form are available as accessors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forms = nil) ⇒ ModelGenerator



89
90
91
92
# File 'lib/ruby-wpdb/gravityforms.rb', line 89

def initialize(forms = nil)
  @forms = Array(forms) || Form.all
  @models = []
end

Instance Attribute Details

#modelsObject (readonly)

Returns the value of attribute models.



87
88
89
# File 'lib/ruby-wpdb/gravityforms.rb', line 87

def models
  @models
end

Instance Method Details

#generateObject



94
95
96
97
98
99
100
101
# File 'lib/ruby-wpdb/gravityforms.rb', line 94

def generate
  @forms.each do |form|
    form_name = WPDB.camelize(form.title)
    form_class = build_class(form)

    @models << WPDB::GravityForms.const_set(form_name, form_class)
  end
end