Module: SchemaReader::ClassMethods

Defined in:
lib/schema_reader.rb

Instance Method Summary collapse

Instance Method Details

#attr_schema(options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/schema_reader.rb', line 29

def attr_schema(options = {})
  table = options.fetch(:table)
  file = options.fetch(:file)
  self.send(:attr_accessor, *read_schema(table, file))
end

#pass_attributes_to_new(bool = true) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/schema_reader.rb', line 21

def pass_attributes_to_new(bool=true)
  if bool
    define_method("initialize") do |options|
      update(options)
    end
  end
end

#read_schema(table_selected, path) ⇒ Object



35
36
37
38
39
40
# File 'lib/schema_reader.rb', line 35

def read_schema(table_selected, path)
  tables = parse_for_tables(path)
  table = find_table(tables, table_selected)
  field_names = get_table_field_name(table)
  add_associations(field_names)
end