class SchemaToScaffold::Schema

Attributes

data[R]
tables[R]

Public Class Methods

new(data) click to toggle source
# File lib/schema_to_scaffold/schema.rb, line 6
def initialize(data)
  @data, @tables = data, Schema.parse(data)
end
parse(data) click to toggle source
# File lib/schema_to_scaffold/schema.rb, line 40
def self.parse(data)
  data.split(/^\s*create_/)[1..-1].map {|table_data| Table.parse(table_data) }.reject{ |e| e.nil? }
end

Public Instance Methods

print_table_names() click to toggle source
select_tables(input) click to toggle source
# File lib/schema_to_scaffold/schema.rb, line 18
def select_tables(input)
  case input
  when "*"
    table_range.to_a
  when /^\d/
    table_range.include?(input.to_i) ? [input.to_i] : []
  end
end
table(id) click to toggle source
# File lib/schema_to_scaffold/schema.rb, line 27
def table(id)
  case id
  when Symbol then table(id.to_s)
  when String then tables[table_names.index(id)]
  when Fixnum then tables[id]
  else nil
  end
end
table_names() click to toggle source
# File lib/schema_to_scaffold/schema.rb, line 10
def table_names
  tables.map(&:name)
end
to_script() click to toggle source
# File lib/schema_to_scaffold/schema.rb, line 36
def to_script
  tables.map(&:to_script)
end

Private Instance Methods

table_range() click to toggle source
# File lib/schema_to_scaffold/schema.rb, line 46
def table_range
  0...table_names.count
end