Module: ActiveAny::Attribute

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_any/attribute.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attribute_for_inspect(attr_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_any/attribute.rb', line 19

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

#attributesObject



7
8
9
# File 'lib/active_any/attribute.rb', line 7

def attributes
  @attributes ||= {}
end

#has_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/active_any/attribute.rb', line 11

def has_attribute?(attribute)
  attributes.key?(attribute)
end

#inspectObject



31
32
33
34
35
36
37
# File 'lib/active_any/attribute.rb', line 31

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) ⇒ Object



15
16
17
# File 'lib/active_any/attribute.rb', line 15

def read_attribute(name)
  attributes.fetch(name)
end