module ActiveAny::Attribute
Public Instance Methods
attribute_for_inspect(attr_name)
click to toggle source
# File lib/active_any/attribute.rb, line 23 def attribute_for_inspect(attr_name) value = read_attribute(attr_name) if value.is_a?(String) && value.length > 50 "#{value[0, 50]}...".inspect elsif value.is_a?(Date) || value.is_a?(Time) %("#{value.to_s(:db)}") else value.inspect end end
attribute_present?(name)
click to toggle source
# File lib/active_any/attribute.rb, line 19 def attribute_present?(name) attributes[name].present? end
attributes()
click to toggle source
# File lib/active_any/attribute.rb, line 7 def attributes @attributes ||= {} end
has_attribute?(attribute)
click to toggle source
# File lib/active_any/attribute.rb, line 11 def has_attribute?(attribute) attributes.key?(attribute) end
inspect()
click to toggle source
# File lib/active_any/attribute.rb, line 35 def inspect inspection = self.class.attribute_names.collect do |name| "#{name}: #{attribute_for_inspect(name)}" if has_attribute?(name) end.compact.join(', ') "#<#{self.class} #{inspection}>" end
read_attribute(name)
click to toggle source
# File lib/active_any/attribute.rb, line 15 def read_attribute(name) attributes.fetch(name) end