Module: RequiresApproval::ClassMethods

Defined in:
lib/requires_approval.rb

Instance Method Summary collapse

Instance Method Details

#prepare_tables_for_requires_approvalObject

adds the correct tables and columns for requires_approval



197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/requires_approval.rb', line 197

def prepare_tables_for_requires_approval
  self.reset_column_information

  # adds is_active to the parent table
  self.add_requires_approval_fields
  self.reset_column_information

  # adds our versions table
  self.drop_versions_table
  self.create_versions_table
  
end

#requires_approval_for(*attrs) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/requires_approval.rb', line 210

def requires_approval_for(*attrs)
  self.set_options(attrs.extract_options!)

  # set up our attributes that require approval
  self.class_attribute :fields_requiring_approval
  self.fields_requiring_approval = attrs.collect(&:to_s)

  # set up delegates
  self.set_up_version_delegates

  # create a blank version before create to handle if no
  # attributes were ever set
  self.before_validation_on_create(
    :latest_unapproved_version_with_nil_check
  )
  
  # create the versions class
  self.create_versions_class
  self.has_many :versions, 
    :class_name => self.versions_class.name,
    :foreign_key => self.versions_foreign_key

  self.has_one :latest_unapproved_version,
    :autosave => true,
    :class_name => self.versions_class.name,
    :foreign_key => self.versions_foreign_key,
    :conditions => [
      "#{self.versions_table_name}.is_approved = ?", false
    ]

  self.set_up_scopes


end

#versions_classObject

the class which our versions are



246
247
248
# File 'lib/requires_approval.rb', line 246

def versions_class
  "#{self.name}::#{self.versions_class_name}".constantize
end