Class: Attribute

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(type, name) ⇒ Attribute

Returns a new instance of Attribute.



78
79
80
# File 'lib/active_hash_ext.rb', line 78

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



76
77
78
# File 'lib/active_hash_ext.rb', line 76

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



76
77
78
# File 'lib/active_hash_ext.rb', line 76

def type
  @type
end

Class Method Details

.parse(attribute) ⇒ Object



86
87
88
89
90
91
# File 'lib/active_hash_ext.rb', line 86

def self.parse(attribute)
  match = attribute.match(/t\.(\w+)\s+"(\w+)"/)
  if match
    Attribute.new(*match.captures)
  end
end

Instance Method Details

#to_scriptObject



82
83
84
# File 'lib/active_hash_ext.rb', line 82

def to_script
  "#{name}:#{type}" unless ["created_at","updated_at"].include? name
end