Class: WPDB::GravityForms::ModelGenerator
- Inherits:
-
Object
- Object
- WPDB::GravityForms::ModelGenerator
- 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
-
#models ⇒ Object
readonly
Returns the value of attribute models.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(forms = nil) ⇒ ModelGenerator
constructor
A new instance of ModelGenerator.
Constructor Details
#initialize(forms = nil) ⇒ ModelGenerator
Returns a new instance of 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
#models ⇒ Object (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
#generate ⇒ Object
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 |