Class: SchemaToScaffold::Schema
- Inherits:
-
Object
- Object
- SchemaToScaffold::Schema
- Defined in:
- lib/schema_to_scaffold/schema.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Schema
constructor
A new instance of Schema.
- #print_table_names ⇒ Object
- #select_tables(input) ⇒ Object
- #table(id) ⇒ Object
- #table_names ⇒ Object
- #to_script ⇒ Object
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/schema_to_scaffold/schema.rb', line 4 def data @data end |
#tables ⇒ Object (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
Instance Method Details
#print_table_names ⇒ Object
14 15 16 |
# File 'lib/schema_to_scaffold/schema.rb', line 14 def print_table_names table_names.each_with_index { |name, i| puts "#{i}. #{name}" } end |
#select_tables(input) ⇒ Object
18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
27 28 29 30 31 32 33 34 |
# 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 Integer then tables[id] else nil end end |
#table_names ⇒ Object
10 11 12 |
# File 'lib/schema_to_scaffold/schema.rb', line 10 def table_names tables.map(&:name) end |
#to_script ⇒ Object
36 37 38 |
# File 'lib/schema_to_scaffold/schema.rb', line 36 def to_script tables.map(&:to_script) end |