Class: Table

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes) ⇒ Table

Returns a new instance of Table.



50
51
52
# File 'lib/active_hash_ext.rb', line 50

def initialize(name, attributes)
  @name, @attributes = name, attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



48
49
50
# File 'lib/active_hash_ext.rb', line 48

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



48
49
50
# File 'lib/active_hash_ext.rb', line 48

def name
  @name
end

Class Method Details

.parse(table_data) ⇒ Object



59
60
61
62
63
64
# File 'lib/active_hash_ext.rb', line 59

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



54
55
56
57
# File 'lib/active_hash_ext.rb', line 54

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