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.3'
Instance Method Summary collapse
- #[](comment) ⇒ Object
- #[]=(comment, value) ⇒ Object
- #attr_name_to_comment(attr_name) ⇒ Object
- #comment_to_attr_name(comment) ⇒ Object
- #comments ⇒ Object
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 |
#attr_name_to_comment(attr_name) ⇒ Object
18 19 20 |
# 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) ⇒ 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 |
#comments ⇒ Object
22 23 24 |
# 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 |