Module: Tablesalt::StringableObject
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/tablesalt/stringable_object.rb
Instance Method Summary collapse
- #attribute_string(method) ⇒ Object private
- #inspect ⇒ Object
- #safe_send(method) ⇒ Object private
- #string_for(method) ⇒ Object private
- #stringable_attribute_values ⇒ Object private
- #stringable_attributes ⇒ Object private
- #to_s ⇒ Object
Instance Method Details
#attribute_string(method) ⇒ Object (private)
25 26 27 |
# File 'lib/tablesalt/stringable_object.rb', line 25 def attribute_string(method) stringable_attribute_values.map { |attribute, value| "#{attribute}=#{value.public_send(method)}" }.join(" ") end |
#inspect ⇒ Object
11 12 13 |
# File 'lib/tablesalt/stringable_object.rb', line 11 def inspect string_for(__method__) end |
#safe_send(method) ⇒ Object (private)
33 34 35 36 37 |
# File 'lib/tablesalt/stringable_object.rb', line 33 def safe_send(method) public_send(method) rescue StandardError nil end |
#string_for(method) ⇒ Object (private)
21 22 23 |
# File 'lib/tablesalt/stringable_object.rb', line 21 def string_for(method) "#<#{self.class.name}#{" #{attribute_string(method)}" unless stringable_attributes.empty?}>" end |
#stringable_attribute_values ⇒ Object (private)
29 30 31 |
# File 'lib/tablesalt/stringable_object.rb', line 29 def stringable_attribute_values stringable_attributes.each_with_object({}) { |attribute, result| result[attribute] = safe_send(attribute) } end |
#stringable_attributes ⇒ Object (private)
17 18 19 |
# File 'lib/tablesalt/stringable_object.rb', line 17 def stringable_attributes [] end |
#to_s ⇒ Object
7 8 9 |
# File 'lib/tablesalt/stringable_object.rb', line 7 def to_s string_for(__method__) end |