Class: DynamicModel::TablesAnalyser

Inherits:
Object
  • Object
show all
Defined in:
lib/database_introspection/dynamic_model/tables_analyser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, base_class = ActiveRecord::Base) ⇒ TablesAnalyser

Returns a new instance of TablesAnalyser.



7
8
9
10
11
12
# File 'lib/database_introspection/dynamic_model/tables_analyser.rb', line 7

def initialize(domain, base_class = ActiveRecord::Base)
  @domain = domain
  @base_class = base_class
  define_domain_module
  @klasses_analysed = []
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



5
6
7
# File 'lib/database_introspection/dynamic_model/tables_analyser.rb', line 5

def domain
  @domain
end

#klasses_analysedObject (readonly)

Returns the value of attribute klasses_analysed.



5
6
7
# File 'lib/database_introspection/dynamic_model/tables_analyser.rb', line 5

def klasses_analysed
  @klasses_analysed
end

Instance Method Details

#scan_databaseObject



14
15
16
17
18
19
20
# File 'lib/database_introspection/dynamic_model/tables_analyser.rb', line 14

def scan_database
  # Introspect database tables and creates ActiveRecord descendants in the name space module
  @domain_module.table_names.map do |table_name|
    inject_class table_name
  end
  @domain_module.model_classes
end