Class: SchemaToScaffold::Table
- Inherits:
-
Object
- Object
- SchemaToScaffold::Table
- Defined in:
- lib/schema_to_scaffold/table.rb
Overview
fetch table names and convert them to a scaffold syntax
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, attributes) ⇒ Table
constructor
A new instance of Table.
- #to_script(target, migragion_flag) ⇒ Object
Constructor Details
#initialize(name, attributes) ⇒ Table
Returns a new instance of Table.
10 11 12 |
# File 'lib/schema_to_scaffold/table.rb', line 10 def initialize(name, attributes) @name, @attributes = name, attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/schema_to_scaffold/table.rb', line 8 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/schema_to_scaffold/table.rb', line 8 def name @name end |
Class Method Details
.parse(table_data) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/schema_to_scaffold/table.rb', line 23 def self.parse(table_data) return unless name = table_data[/table "([^"]+?)"/] name = $1 atts = table_data.lines.to_a.select {|line| line =~ /t\.\w+/ }.map {|att| Attribute.parse att } Table.new(name, atts) end |
Instance Method Details
#to_script(target, migragion_flag) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/schema_to_scaffold/table.rb', line 14 def to_script(target,migragion_flag) attributes_list = attributes.map(&:to_script).reject{|x| x.nil? || x.empty?}.join(' ') script = [] script << "rails generate #{target} #{modelize name} #{attributes_list}" script << " --no-migration" unless migragion_flag script << "\n\n" return script end |