Module: CommentAttribute

Extended by:
ActiveSupport::Concern
Defined in:
lib/comment_attribute/version.rb,
lib/comment_attribute/comment_attribute.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Instance Method Details

#[](comment) ⇒ Object



4
5
6
7
# 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) ⇒ Object



9
10
11
12
# 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

#comment_to_attr_name(comment) ⇒ Object



14
15
16
# 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