Class: DynamicFormModel

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dynamic_form_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_exists?(class_name) ⇒ Boolean

checks to see if class name exists as a static model or has already been declared used with sunspot_setup_all

Returns:

  • (Boolean)

43
44
45
46
47
48
49
50
51
52
# File 'app/models/dynamic_form_model.rb', line 43

def self.class_exists?(class_name)
  result = nil
  begin
    klass = Module.const_get(class_name)
    result = (klass.is_a?(Class) ? ((klass.superclass == ActiveRecord::Base or klass.superclass == DynamicFormModel) ? true : nil) : nil)
  rescue NameError
    result = nil
  end
  result
end

.get_constant(klass_name) ⇒ Object


30
31
32
33
34
35
36
37
38
39
# File 'app/models/dynamic_form_model.rb', line 30

def self.get_constant(klass_name)
	result = nil
	begin
    result = klass_name.constantize
  rescue
    DynamicFormDocument.declare(klass_name)
    result = klass_name.constantize
  end
	result
end

.get_instance(klass_name) ⇒ Object


54
55
56
# File 'app/models/dynamic_form_model.rb', line 54

def self.get_instance(klass_name)
  DynamicFormModel.get_constant(klass_name).new
end

.sunspot_setup_allObject


22
23
24
25
26
27
28
# File 'app/models/dynamic_form_model.rb', line 22

def self.sunspot_setup_all
  DynamicFormModel.all.each do |m|
    next if m.model_name == 'DynamicFormDocument'
    next unless ActiveRecord::Base.connection.table_exists? m.get_constant.table_name
    m.get_constant.sunspot_setup unless DynamicFormModel.class_exists?(m.model_name)
  end
end

Instance Method Details

#create_roleObject


10
11
12
# File 'app/models/dynamic_form_model.rb', line 10

def create_role
  SecurityRole.create(:description => self.model_name.titleize.pluralize, :internal_identifier => role_iid) if self.role.nil?
end

#get_constantObject


58
59
60
# File 'app/models/dynamic_form_model.rb', line 58

def get_constant
  DynamicFormModel.get_constant(self.model_name)
end

#get_instanceObject


62
63
64
# File 'app/models/dynamic_form_model.rb', line 62

def get_instance
  DynamicFormModel.get_instance(self.model_name)
end

#roleObject


18
19
20
# File 'app/models/dynamic_form_model.rb', line 18

def role
  SecurityRole.iid(role_iid)
end

#role_iidObject


14
15
16
# File 'app/models/dynamic_form_model.rb', line 14

def role_iid
  "dynamic_form_model_#{self.model_name}"
end