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.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



80
81
82
# File 'lib/active_hash_ext.rb', line 80

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



80
81
82
# File 'lib/active_hash_ext.rb', line 80

def type
  @type
end

Class Method Details

.parse(attribute) ⇒ Object



90
91
92
93
94
95
# File 'lib/active_hash_ext.rb', line 90

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

Instance Method Details

#to_scriptObject



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

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