Class: SchemaToScaffold::Attribute
- Inherits:
-
Object
- Object
- SchemaToScaffold::Attribute
- Defined in:
- lib/schema_to_scaffold/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, type) ⇒ Attribute
constructor
A new instance of Attribute.
- #to_script ⇒ Object
Constructor Details
#initialize(name, type) ⇒ Attribute
Returns a new instance of Attribute.
6 7 8 |
# File 'lib/schema_to_scaffold/attribute.rb', line 6 def initialize(name, type) @name, @type = name, type end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/schema_to_scaffold/attribute.rb', line 4 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/schema_to_scaffold/attribute.rb', line 4 def type @type end |
Class Method Details
.parse(attribute) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/schema_to_scaffold/attribute.rb', line 14 def self.parse(attribute) match = attribute.match(/t\.(\w+)\s+"(\w+)"/) if match name = match.captures[1].sub(/_id$/, "") type = $&.nil? ? match.captures[0] : "references" Attribute.new(name, type) end end |
Instance Method Details
#to_script ⇒ Object
10 11 12 |
# File 'lib/schema_to_scaffold/attribute.rb', line 10 def to_script "#{name}:#{type}" unless ["created_at","updated_at"].include?(name) end |