Module: TracksAttributes::TracksAttributesInternal::ClassMethods

Defined in:
lib/tracks_attributes.rb

Instance Method Summary collapse

Instance Method Details

#accessorsObject

return an array of all of the attributes that are not in active record



122
123
124
# File 'lib/tracks_attributes.rb', line 122

def accessors
  @tracked_attrs.keys ||= []
end

#attr_accessor(*vars) ⇒ Object

Override attr_accessor to track accessors for an TracksAttributes. If the last argument may be a Hash of options where the options may be:

  • klass - the Class of the attribute to create when re-hydrating

    the instance from a Hash/JSON/XML
    


90
91
92
# File 'lib/tracks_attributes.rb', line 90

def attr_accessor(*vars)
  super *(add_tracked_attrs(true, true, *vars))
end

#attr_info_for(attribute_name) ⇒ Object

return the attribute information for the provided attribute



127
128
129
# File 'lib/tracks_attributes.rb', line 127

def attr_info_for(attribute_name)
  @tracked_attrs[attribute_name.to_sym]
end

#attr_reader(*vars) ⇒ Object

Override attr_reader to track accessors for an TracksAttributes. If the last argument may be a Hash of options where the options may be:

  • klass - the Class of the attribute to create when re-hydrating

    the instance from a Hash/JSON/XML
    


101
102
103
# File 'lib/tracks_attributes.rb', line 101

def attr_reader(*vars)
  super *(add_tracked_attrs(true, false, *vars))
end

#attr_writer(*vars) ⇒ Object

Override attr_writer to track accessors for an TracksAttributes. If the last argument may be a Hash of options where the options may be:

  • klass - the Class of the attribute to create when re-hydrating

    the instance from a Hash/JSON/XML
    


112
113
114
115
116
117
118
119
# File 'lib/tracks_attributes.rb', line 112

def attr_writer(*vars)
  # avoid tracking attributes that are added by the class_attribute
  # as these are class attributes and not instance attributes.
  tracked_vars = vars.reject {|var| respond_to? var }
  add_tracked_attrs(false, true, *tracked_vars)
  vars.extract_options!
  super
end

#enable_validationsObject

turn on ActiveModel:Validation validations



132
133
134
# File 'lib/tracks_attributes.rb', line 132

def enable_validations
  include ActiveModel::Validations unless respond_to?(:_validators)
end