Class: SchemaToScaffold::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_to_scaffold/schema.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Schema

Returns a new instance of Schema.



6
7
8
# File 'lib/schema_to_scaffold/schema.rb', line 6

def initialize(data)
  @data, @tables = data, Schema.parse(data)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/schema_to_scaffold/schema.rb', line 4

def data
  @data
end

#tablesObject (readonly)

Returns the value of attribute tables.



4
5
6
# File 'lib/schema_to_scaffold/schema.rb', line 4

def tables
  @tables
end

Class Method Details

.parse(data) ⇒ Object



27
28
29
# File 'lib/schema_to_scaffold/schema.rb', line 27

def self.parse(data)
  data.split(/^\s*create_/)[1..-1].map {|table_data| Table.parse table_data }
end

Instance Method Details

#table(id) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/schema_to_scaffold/schema.rb', line 14

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_namesObject



10
11
12
# File 'lib/schema_to_scaffold/schema.rb', line 10

def table_names
  tables.map(&:name)
end

#to_scriptObject



23
24
25
# File 'lib/schema_to_scaffold/schema.rb', line 23

def to_script
  tables.map(&:to_script)
end