module CommentAttribute

Constants

VERSION

Public Instance Methods

[](comment) click to toggle source
Calls superclass method
# File lib/comment_attribute/comment_attribute.rb, line 4
def [](comment)
  attr_name = comment_to_attr_name(comment) || comment
  super(attr_name)
end
[]=(comment, value) click to toggle source
Calls superclass method
# File lib/comment_attribute/comment_attribute.rb, line 9
def []=(comment, value)
  attr_name = comment_to_attr_name(comment) || comment
  super(attr_name, value)
end
attr_name_to_comment(attr_name) click to toggle source
# File lib/comment_attribute/comment_attribute.rb, line 18
def attr_name_to_comment(attr_name)
  self.class.columns.find{|r| r.name == attr_name.to_s }&.comment
end
comment_to_attr_name(comment) click to toggle source
# File lib/comment_attribute/comment_attribute.rb, line 14
def comment_to_attr_name(comment)
  self.class.columns.find{|r| r.comment == comment }&.name
end
comments() click to toggle source
# File lib/comment_attribute/comment_attribute.rb, line 22
def comments
  Hash[*attributes.map{|k, v| [attr_name_to_comment(k) || k, v]}.flatten]
end