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, migration_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
Instance Method Details
#to_script(target, migration_flag) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/schema_to_scaffold/table.rb', line 14 def to_script(target, migration_flag) begin attributes_list = attributes.map(&:to_script).reject { |x| x.nil? || x.empty? }.join(' ') rescue => e puts "\n ---------------------------------------------" puts e. puts "Table \n\n\n #{self.inspect} \n\n\n" puts "\n ---------------------------------------------" end script = [] script << "rails generate #{target} #{modelize(name)} #{attributes_list}" script << " --no-migration" unless migration_flag script << "\n\n" script end |