Class: Table
- Inherits:
-
Object
- Object
- Table
- Defined in:
- lib/active_hash_ext.rb
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) ⇒ Object
Constructor Details
#initialize(name, attributes) ⇒ Table
Returns a new instance of Table.
54 55 56 |
# File 'lib/active_hash_ext.rb', line 54 def initialize(name, attributes) @name, @attributes = name, attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
52 53 54 |
# File 'lib/active_hash_ext.rb', line 52 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
52 53 54 |
# File 'lib/active_hash_ext.rb', line 52 def name @name end |
Class Method Details
.parse(table_data) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/active_hash_ext.rb', line 63 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) ⇒ Object
58 59 60 61 |
# File 'lib/active_hash_ext.rb', line 58 def to_script(target) return "rails generate #{target} #{modelize name} #{attributes.map(&:to_script).reject{|x| x.nil? || x.empty?}.join(' ')}" if target == "scaffold" return "rails generate #{target} #{modelize name} #{attributes.map(&:to_script).reject{|x| x.nil? || x.empty?}.join(' ')}" if target == "factory_girl:model" end |